Documentation ¶
Index ¶
- Variables
- func Middleware(config Config) func(http.Handler) http.Handler
- type Config
- type Data
- type Flash
- func (f *Flash) Add(key string, value interface{})
- func (f *Flash) Changed() bool
- func (f *Flash) Clear()
- func (f *Flash) Clone() *Flash
- func (f *Flash) Count() int
- func (f *Flash) Del(key string)
- func (f *Flash) Get(key string) interface{}
- func (f *Flash) GetBool(key string) bool
- func (f *Flash) GetFloat32(key string) float32
- func (f *Flash) GetFloat64(key string) float64
- func (f *Flash) GetInt(key string) int
- func (f *Flash) GetInt64(key string) int64
- func (f *Flash) GetString(key string) string
- func (f *Flash) Has(key string) bool
- func (f *Flash) Set(key string, value interface{})
- func (f *Flash) Values(key string) []interface{}
- type Manager
- func (m *Manager) Destroy(ctx context.Context, s *Session) error
- func (m *Manager) Get(r *http.Request, name string) (*Session, error)
- func (m *Manager) Middleware() func(http.Handler) http.Handler
- func (m *Manager) Regenerate(ctx context.Context, s *Session) error
- func (m *Manager) Renew(ctx context.Context, s *Session) error
- func (m *Manager) Save(ctx context.Context, w http.ResponseWriter, s *Session) error
- type Secure
- type Session
- func (s *Session) Changed() bool
- func (s *Session) Del(key string)
- func (s *Session) Destroy() error
- func (s *Session) 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() error
- func (s *Session) Renew() error
- func (s *Session) Set(key string, value interface{})
- type Store
- type StoreCoder
- type StoreDecoder
- type StoreEncoder
- 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 // ResaveAfter is the time to wait before resave since last timestamp ResaveAfter time.Duration // 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 session id generator GenerateID func() string }
Config is the session manager config
type Flash ¶ added in v0.13.0
type Flash struct {
// contains filtered or unexported fields
}
Flash type
func (*Flash) GetFloat32 ¶ added in v0.13.0
GetFloat32 gets float32 from flash
func (*Flash) GetFloat64 ¶ added in v0.13.0
GetFloat64 gets float64 from flash
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.
func (*Manager) Regenerate ¶ added in v0.13.0
Regenerate regenerates session id use when change user access level to prevent session fixation
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
Destroy destroys session from store
Can use only with middleware
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) 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
Regenerate regenerates session id use when change user access level to prevent session fixation
Can use only with middleware
type Store ¶
type Store interface { Get(ctx context.Context, key string) (Data, error) Set(ctx context.Context, key string, value Data, opt StoreOption) error Del(ctx context.Context, key string) error }
Store interface
type StoreCoder ¶ added in v0.14.0
type StoreCoder interface { NewEncoder(w io.Writer) StoreEncoder NewDecoder(r io.Reader) StoreDecoder }
StoreCoder interface
var DefaultStoreCoder StoreCoder = defaultStoreCoder{}
DefaultStoreCoder is the default store coder
type StoreDecoder ¶ added in v0.14.0
type StoreDecoder interface {
Decode(e interface{}) error
}
StoreDecoder interface
type StoreEncoder ¶ added in v0.14.0
type StoreEncoder interface {
Encode(e interface{}) error
}
StoreEncoder interface