Documentation ¶
Index ¶
- func Register(providerName string, provider Provider) error
- type Config
- type Cookie
- type Dao
- type Dict
- type Encrypt
- type Provider
- type ProviderConfig
- type Session
- func (s *Session) Destroy(ctx *fasthttp.RequestCtx) error
- func (s *Session) Get(ctx *fasthttp.RequestCtx) (Storer, error)
- func (s *Session) Regenerate(ctx *fasthttp.RequestCtx) (Storer, error)
- func (s *Session) Save(ctx *fasthttp.RequestCtx, store Storer)
- func (s *Session) SetProvider(name string, cfg ProviderConfig) error
- type Store
- func (s *Store) DataPointer() *Dict
- func (s *Store) Delete(key string)
- func (s *Store) DeleteBytes(key []byte)
- func (s *Store) Flush()
- func (s *Store) Get(key string) interface{}
- func (s *Store) GetAll() Dict
- func (s *Store) GetBytes(key []byte) interface{}
- func (s *Store) GetExpiration() time.Duration
- func (s *Store) GetSessionID() []byte
- func (s *Store) HasExpirationChanged() bool
- func (s *Store) Init(sessionID []byte, defaultExpiration time.Duration)
- func (s *Store) Reset()
- func (s *Store) Save() error
- func (s *Store) Set(key string, value interface{})
- func (s *Store) SetBytes(key []byte, value interface{})
- func (s *Store) SetExpiration(expiration time.Duration) error
- func (s *Store) SetSessionID(id []byte)
- type Storer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { // cookie name CookieName string // cookie domain Domain string // If you want to delete the cookie when the browser closes, set it to -1. // // 0 means no expire, (24 years) // -1 means when browser closes // >0 is the time.Duration which the session cookies should expire. Expires time.Duration // gc life time to execute it GCLifetime time.Duration // set whether to pass this bar cookie only through HTTPS Secure bool // sessionID is in url query SessionIDInURLQuery bool // sessionName in url query SessionNameInURLQuery string // sessionID is in http header SessionIDInHTTPHeader bool // sessionName in http header SessionNameInHTTPHeader string // SessionIDGeneratorFunc should returns a random session id. SessionIDGeneratorFunc func() []byte // IsSecureFunc should return whether the communication channel is secure // in order to set the secure flag to true according to Secure flag. IsSecureFunc func(*fasthttp.RequestCtx) bool // contains filtered or unexported fields }
Config config struct
func NewDefaultConfig ¶
func NewDefaultConfig() *Config
NewDefaultConfig return new default configuration
type Cookie ¶
type Cookie struct{}
Cookie cookie struct
func (*Cookie) Delete ¶
func (c *Cookie) Delete(ctx *fasthttp.RequestCtx, name string)
Delete delete cookie by cookie name
type Encrypt ¶
type Encrypt struct{}
Encrypt encrypt struct
func (*Encrypt) Base64Decode ¶
Base64Decode base64 decode
func (*Encrypt) Base64Encode ¶
Base64Encode base64 encode
func (*Encrypt) MSGPDecode ¶
MSGPDecode MessagePack decode
type Provider ¶
type Provider interface { Init(expiration time.Duration, cfg ProviderConfig) error Get(id []byte) (Storer, error) Put(store Storer) Destroy(id []byte) error Regenerate(oldID, newID []byte) (Storer, error) // the expiration is also reset to original value Count() int NeedGC() bool GC() }
Provider provider interface
type ProviderConfig ¶
type ProviderConfig interface {
Name() string
}
ProviderConfig provider config interface
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session session struct
func (*Session) Destroy ¶
func (s *Session) Destroy(ctx *fasthttp.RequestCtx) error
Destroy destroy session in fasthttp ctx
func (*Session) Get ¶
func (s *Session) Get(ctx *fasthttp.RequestCtx) (Storer, error)
Get get user session from provider 1. get sessionID from fasthttp ctx 2. if sessionID is empty, generator sessionID and set response Set-Cookie 3. return session provider store
func (*Session) Regenerate ¶
func (s *Session) Regenerate(ctx *fasthttp.RequestCtx) (Storer, error)
Regenerate regenerate a session id for this Storer
func (*Session) Save ¶
func (s *Session) Save(ctx *fasthttp.RequestCtx, store Storer)
Save save the user session with current store
Use this function if you want to avoid some extra-allocations This will save the store into provider and will return it to the pool
Warning: Don't use more the store after exec this function, because, you will lose the after data For avoid it, defer this function in your request handler
func (*Session) SetProvider ¶
func (s *Session) SetProvider(name string, cfg ProviderConfig) error
SetProvider set session provider and provider config
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store store
func (*Store) GetExpiration ¶ added in v1.1.0
GetExpiration get expiration for the session
func (*Store) HasExpirationChanged ¶ added in v1.1.0
HasExpirationChanged check wether the expiration has been changed
func (*Store) SetExpiration ¶ added in v1.1.0
SetExpiration set expiration for the session
type Storer ¶
type Storer interface { Save() error Get(key string) interface{} GetBytes(key []byte) interface{} GetAll() Dict Set(key string, value interface{}) SetBytes(key []byte, value interface{}) Delete(key string) DeleteBytes(key []byte) Flush() GetSessionID() []byte SetExpiration(expiration time.Duration) error GetExpiration() time.Duration HasExpirationChanged() bool }
Storer session store interface