Documentation ¶
Index ¶
- func NewCookie(name, value string, options *Options) *http.Cookie
- func Save(ht *khttp.Transport) error
- type CookieStore
- type GobSerializer
- type JSONSerializer
- type MultiError
- type Options
- type RedisStore
- func (s *RedisStore) Get(ht *khttp.Transport, name string) (*Session, error)
- func (s *RedisStore) New(ht *khttp.Transport, name string) (*Session, error)
- func (s *RedisStore) Save(ht *khttp.Transport, session *Session) error
- func (s *RedisStore) SetKeyPrefix(p string)
- func (s *RedisStore) SetMaxAge(v int)
- func (s *RedisStore) SetMaxLength(l int)
- func (s *RedisStore) SetSerializer(ss SessionSerializer)
- type Registry
- type Session
- type SessionSerializer
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CookieStore ¶
type CookieStore struct { Options *Options Codecs []securecookie.Codec }
CookieStore stores sessions using secure cookies.
func NewCookieStore ¶
func NewCookieStore(keyPairs ...[]byte) *CookieStore
NewCookieStore returns a new CookieStore.
Keys are defined in pairs to allow key rotation, but the common case is to set a single authentication key and optionally an encryption key.
The first key in a pair is used for authentication and the second for encryption. The encryption key can be set to nil or omitted in the last pair, but the authentication key is required in all pairs.
It is recommended to use an authentication key with 32 or 64 bytes. The encryption key, if set, must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256 modes.
func (*CookieStore) Get ¶
Get returns a session for the given name after adding it to the registry.
It returns a new session if the sessions doesn't exist. Access IsNew on the session to check if it is an existing session or a new one.
It returns a new session and an error if the session exists but could not be decoded.
func (*CookieStore) MaxAge ¶
func (s *CookieStore) MaxAge(age int)
MaxAge sets the maximum age for the store and the underlying cookie implementation. Individual sessions can be deleted by setting Options.MaxAge = -1 for that session.
type GobSerializer ¶
type GobSerializer struct{}
GobSerializer uses gob package to encode the session map
func (GobSerializer) Deserialize ¶
func (s GobSerializer) Deserialize(d []byte, ss *Session) error
type JSONSerializer ¶
type JSONSerializer struct{}
JSONSerializer encode the session map to JSON.
func (JSONSerializer) Deserialize ¶
func (s JSONSerializer) Deserialize(d []byte, ss *Session) error
type MultiError ¶
type MultiError []error
MultiError stores multiple errors.
Borrowed from the App Engine SDK.
func (MultiError) Error ¶
func (m MultiError) Error() string
type Options ¶
type Options struct { Path string Domain string // MaxAge=0 means no Max-Age attribute specified and the cookie will be // deleted after the browser session ends. // MaxAge<0 means delete cookie immediately. // MaxAge>0 means Max-Age attribute present and given in seconds. MaxAge int Secure bool HttpOnly bool SameSite http.SameSite }
Options stores configuration for a session or session store.
Fields are a subset of http.Cookie fields.
type RedisStore ¶
type RedisStore struct { Options *Options Codecs []securecookie.Codec DefaultMaxAge int // contains filtered or unexported fields }
RedisStore stores sessions in a redis backend.
func NewRedisStore ¶
func NewRedisStore(rdCmd redis.Cmdable, keyPairs ...[]byte) (*RedisStore, error)
func (*RedisStore) SetKeyPrefix ¶
func (s *RedisStore) SetKeyPrefix(p string)
SetKeyPrefix set the prefix
func (*RedisStore) SetMaxAge ¶
func (s *RedisStore) SetMaxAge(v int)
func (*RedisStore) SetMaxLength ¶
func (s *RedisStore) SetMaxLength(l int)
func (*RedisStore) SetSerializer ¶
func (s *RedisStore) SetSerializer(ss SessionSerializer)
SetSerializer sets the serializer
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores sessions used during a request.
func GetRegistry ¶
GetRegistry returns a registry instance for the current request.
type Session ¶
type Session struct { Values map[any]any Options *Options ID string IsNew bool // contains filtered or unexported fields }
Session stores the values and optional configuration for a session.
func NewSession ¶
NewSession is called by session stores to create a new session instance.
func (*Session) AddFlash ¶
AddFlash adds a flash message to the session.
A single variadic argument is accepted, and it is optional: it defines the flash key. If not defined "_flash" is used by default.
func (*Session) Flashes ¶
Flashes returns a slice of flash messages from the session.
A single variadic argument is accepted, and it is optional: it defines the flash key. If not defined "_flash" is used by default.