session

package
v0.0.0-...-6b2826c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2024 License: AGPL-3.0 Imports: 3 Imported by: 4

Documentation

Index

Constants

View Source
const ServiceName service.Name = "session"

ServiceName defines the Session service name

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseFlash

type BaseFlash struct {
	// contains filtered or unexported fields
}

BaseFlash is a base implementation of a flash message

func NewBaseFlash

func NewBaseFlash(flashType FlashType, message string) *BaseFlash

NewBaseFlash returns a new BaseFlash

func (*BaseFlash) Message

func (f *BaseFlash) Message() string

Message returns the message of the flash

func (*BaseFlash) Type

func (f *BaseFlash) Type() FlashType

Type returns the type of the flash

type Flash

type Flash interface {
	Type() FlashType
	Message() string
}

Flash is a ephemeral message that lives in a session until it's read

type FlashType

type FlashType string

FlashType defines the type of a flash message

const (
	// FlashError defines an "error" flash message
	FlashError FlashType = "error"
	// FlashWarn defines an "warning" flash message
	FlashWarn FlashType = "warn"
	// FlashSuccess defines an "success" flash message
	FlashSuccess FlashType = "success"
	// FlashInfo defines an "info" flash message
	FlashInfo FlashType = "info"
)

type Service

type Service interface {
	Get(http.ResponseWriter, *http.Request) (Session, error)
}

Service defines the API of a "http session" service

func From

func From(container *service.Container) (Service, error)

From retrieves the session service in the given container

func Must

func Must(container *service.Container) Service

Must retrieves the session service in the given container or panic otherwise

type Session

type Session interface {
	Set(string, interface{})
	Unset(string)
	Get(string) interface{}
	AddFlash(flashType FlashType, message string)
	Flashes(flashTypes ...FlashType) []Flash
	Save(http.ResponseWriter, *http.Request) error
	Delete(http.ResponseWriter, *http.Request) error
}

Session defines the API of a Session

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL