Documentation ¶
Index ¶
- func Del(ctx context.Context, key string) error
- func Get(ctx context.Context, key string) (string, error)
- func NewCookieStore(config CookieStoreConfig) *sessions.CookieStore
- func Put(ctx context.Context, key, value string) error
- func WithSession(conf *CookieStoreConfig) func(http.Handler) http.Handler
- type CookieStoreConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewCookieStore ¶
func NewCookieStore(config CookieStoreConfig) *sessions.CookieStore
NewCookieStore initializes a `gorilla/sessions.CookieStore` by `CookieStoreConfig`.
The `gorilla/sessions.CookieStore`: https://github.com/gorilla/sessions/blob/7910f5bb5ac86ab08f97d8bda39b476fc117b684/store.go#L66-L70
func WithSession ¶
func WithSession(conf *CookieStoreConfig) func(http.Handler) http.Handler
WithSession is middleware to generate a session store for the whole request lifetime. later session operations should call `Get`/`Put`/`Del` to work with the session
Types ¶
type CookieStoreConfig ¶
type CookieStoreConfig struct { Name string `required:"true"` Key string `required:"true"` Domain string Path string `default:"/"` MaxAge int `default:"2592000"` // 2592000 = 30 * 24 * 60 * 60 NoHTTPOnly bool NoSecure bool }
CookieStoreConfig is a general cookie storage configuration. It extends the `gorilla/sessions.Options` and compatible to work with `jinzhu/configor.Load` to be convenient to: * Set the least required fields * Enable the *Secure* and *HttpOnly* by default * Set default value for `Path` and `MaxAge`
The `gorilla/sessions.Options`: https://github.com/gorilla/sessions/blob/7910f5bb5ac86ab08f97d8bda39b476fc117b684/sessions.go#L19-L34