Documentation
¶
Overview ¶
Package session provides session management functionality, including secure cookies, session storage, and session encoding/decoding using CBOR and secure cookies.
Index ¶
- func DecodeMulti(name, value string, dst any, codecs ...Codec) error
- func EncodeMulti(name string, value any, codecs ...Codec) (string, error)
- func GenerateRandomKey(length int) []byte
- func NewCookie(name, value string, options *Options, now func() time.Time) *http.Cookie
- type CBOREncoder
- type Codec
- type CookieStore
- type Options
- type Registry
- type SecureCookie
- type Serializer
- type Session
- type Store
- type Values
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateRandomKey ¶
Types ¶
type CBOREncoder ¶
type CBOREncoder struct{}
CBOREncoder encodes and decodes values using CBOR.
func (CBOREncoder) Deserialize ¶
func (e CBOREncoder) Deserialize(src []byte, dst any) error
Deserialize decodes a value using CBOR.
type Codec ¶
type CookieStore ¶
CookieStore stores sessions using secure cookies.
func NewCookieStore ¶
func NewCookieStore(now func() time.Time, keyPairs ...[]byte) *CookieStore
func (*CookieStore) MaxAge ¶
func (s *CookieStore) MaxAge(age int)
func (*CookieStore) New ¶
New returns a session for the given name without adding it to the registry.
The difference between New() and Get() is that calling New() twice will decode the session data twice, while Get() registers and reuses the same decoded session after the first call.
func (*CookieStore) Save ¶
func (s *CookieStore) Save(r *http.Request, w http.ResponseWriter, session *Session) error
Save adds a single session to the response.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores sessions used during a request.
type SecureCookie ¶
type SecureCookie struct {
// contains filtered or unexported fields
}
SecureCookie encodes and decodes authenticated and optionally encrypted cookie values.
func NewSecureCookie ¶
func NewSecureCookie(hashKey, blockKey []byte, now func() time.Time) *SecureCookie
func (*SecureCookie) BlockFunc ¶
func (s *SecureCookie) BlockFunc(f func([]byte) (cipher.Block, error)) *SecureCookie
func (*SecureCookie) MaxAge ¶
func (s *SecureCookie) MaxAge(value int) *SecureCookie
MaxAge restricts the maximum age, in seconds, for the cookie value.
Default is 86400 * 30. Set it to 0 for no restriction.
type Serializer ¶
type Serializer interface {
Serialize(src any) ([]byte, error)
Deserialize(src []byte, dst any) error
}
Serializer provides an interface for providing custom serializers for cookie values.
type Session ¶
type Session struct {
Options *Options
ID string
Values Values
IsNew bool
// contains filtered or unexported fields
}