Documentation ¶
Index ¶
- Constants
- Variables
- func NewContext(ctx context.Context, s *Session) context.Context
- type MemorySessionStore
- type Middleware
- type Session
- func (s *Session) Decode(data string) error
- func (s *Session) Del(key interface{}) error
- func (s *Session) Encode() (string, error)
- func (s *Session) Get(key interface{}, dst interface{}) error
- func (s *Session) IsExpired(maxAge time.Duration) bool
- func (s *Session) Set(key interface{}, value interface{}) error
- type SessionStore
Constants ¶
View Source
const SessionLoggerKey = "web.middleware.session"
SessionLoggerKey is a logger key for the middleware
Variables ¶
View Source
var Default = &Middleware{ Store: NewMemorySessionStore(), CookieName: "yssk22-go-session", MaxAge: 7 * 24 * time.Hour, Domain: "localhost", HttpOnly: true, Path: "/", }
Default is a middleware instance with default value
Functions ¶
Types ¶
type MemorySessionStore ¶
type MemorySessionStore struct {
// contains filtered or unexported fields
}
MemorySessionStore implements SessionStore on Memory
func NewMemorySessionStore ¶
func NewMemorySessionStore() *MemorySessionStore
func (*MemorySessionStore) Del ¶
func (s *MemorySessionStore) Del(ctx context.Context, session *Session) error
Del implements SessionStore#Del
func (*MemorySessionStore) Set ¶
func (s *MemorySessionStore) Set(ctx context.Context, session *Session) error
Set implements SessionStore#Set
func (*MemorySessionStore) String ¶
func (s *MemorySessionStore) String() string
type Middleware ¶
type Middleware struct { Store SessionStore // // Configurations for cookie that keeps session id. // CookieName string MaxAge time.Duration Domain string HttpOnly bool Path string }
func NewMiddleware ¶
func NewMiddleware(store SessionStore) *Middleware
NewMiddleware returns the *Middleware with default configurations.
func (*Middleware) Process ¶
func (m *Middleware) Process(req *web.Request, next web.NextHandler) *response.Response
type Session ¶
type Session struct { ID uuid.UUID CSRFSecret uuid.UUID Timestamp time.Time Data map[string][]byte // contains filtered or unexported fields }
Session is an object to represents session
func FromContext ¶
FromContext returns a *Session from a context.
func FromRequest ¶
FromRequest returns a *Session from a request.
func (*Session) Encode ¶
Encode returns a encoded strings of session data, which is passed to session store.
Directories ¶
Path | Synopsis |
---|---|
Package sessiontest provides session test helper
|
Package sessiontest provides session test helper |
Click to show internal directories.
Click to hide internal directories.