Documentation
¶
Index ¶
- Variables
- func Middleware(config Config) func(http.Handler) http.Handler
- type Config
- type Data
- type Manager
- type Secure
- type Session
- func (s *Session) Changed() bool
- func (s *Session) Del(key string)
- func (s *Session) Destroy()
- func (s *Session) Flash() *flash.Flash
- func (s *Session) Get(key string) interface{}
- func (s *Session) GetBool(key string) bool
- func (s *Session) GetFloat32(key string) float32
- func (s *Session) GetFloat64(key string) float64
- func (s *Session) GetInt(key string) int
- func (s *Session) GetInt64(key string) int64
- func (s *Session) GetString(key string) string
- func (s *Session) Hijacked() bool
- func (s *Session) ID() string
- func (s *Session) IsNew() bool
- func (s *Session) Pop(key string) interface{}
- func (s *Session) PopBool(key string) bool
- func (s *Session) PopFloat32(key string) float32
- func (s *Session) PopFloat64(key string) float64
- func (s *Session) PopInt(key string) int
- func (s *Session) PopInt64(key string) int64
- func (s *Session) PopString(key string) string
- func (s *Session) Regenerate()
- func (s *Session) Renew()
- func (s *Session) Set(key string, value interface{})
- type Store
- type StoreOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is the error when session not found // store must return ErrNotFound if session data not exists ErrNotFound = errors.New("session: not found") )
Errors
var (
ErrNotPassMiddleware = errors.New("session: request not pass middleware")
)
Errors
var (
HijackedTime = 5 * time.Minute
)
Global Session Config
Functions ¶
Types ¶
type Config ¶
type Config struct { Store Store // Secret is the salt for hash session id before put to store Secret []byte // Keys is the keys to sign session id Keys [][]byte // Cookie config Domain string HTTPOnly bool Path string MaxAge time.Duration Secure Secure SameSite http.SameSite // IdleTimeout is the ttl for storage // if IdleTimeout is zero, it will use MaxAge IdleTimeout time.Duration // DeleteOldSession deletes the old session from store when regenerate, // better not to delete old session to avoid user loss session when unstable network DeleteOldSession bool // Resave forces session to save to store even if session was not modified Resave bool // Rolling, set cookie every responses Rolling bool // Proxy, also checks X-Forwarded-Proto when use prefer secure Proxy bool // DisablaHashID disables hash session id when save to store DisableHashID bool // GenerateID is the generate id function GenerateID func() string }
Config is the session manager config
type Manager ¶ added in v0.2.0
type Manager struct {
// contains filtered or unexported fields
}
Manager is the session manager
func (*Manager) Middleware ¶ added in v0.4.0
Middleware injects session manager into request's context.
All data changed before write response writer's header will be save.
type Session ¶
type Session struct { // cookie config Name string Domain string Path string HTTPOnly bool MaxAge time.Duration Secure bool SameSite http.SameSite Rolling bool // contains filtered or unexported fields }
Session type
func (*Session) Destroy ¶ added in v0.0.4
func (s *Session) Destroy()
Destroy destroys session from store
func (*Session) GetFloat32 ¶ added in v0.5.0
GetFloat32 gets float32 from session
func (*Session) GetFloat64 ¶ added in v0.5.0
GetFloat64 gets float64 from session
func (*Session) Hijacked ¶ added in v0.4.0
Hijacked checks is session was hijacked, can use only with Manager
func (*Session) PopFloat32 ¶ added in v0.5.0
PopFloat32 pops float32 from session
func (*Session) PopFloat64 ¶ added in v0.5.0
PopFloat64 pops float64 from session
func (*Session) Regenerate ¶ added in v0.5.0
func (s *Session) Regenerate()
Regenerate regenerates session id use when change user access level to prevent session fixation
can not use regenerate and destroy same time Regenerate can call only one time
type Store ¶
type Store interface { Get(key string, opt StoreOption) (Data, error) Set(key string, value Data, opt StoreOption) error Del(key string, opt StoreOption) error }
Store interface
type StoreOption ¶ added in v0.5.0
StoreOption type