Documentation ¶
Index ¶
- Constants
- func GorillaSessions(name string, store Store) gin.HandlerFunc
- func Sessions(name string, store Store) gin.HandlerFunc
- type GormStore
- func (st *GormStore) Cleanup()
- func (st *GormStore) Get(r *http.Request, name string) (*gsessions.Session, error)
- func (st *GormStore) MaxAge(age int)
- func (st *GormStore) MaxLength(l int)
- func (st *GormStore) New(r *http.Request, name string) (*gsessions.Session, error)
- func (st *GormStore) Options(options Options)
- func (st *GormStore) RenewID(r *http.Request, w http.ResponseWriter, session *gsessions.Session) error
- func (st *GormStore) Save(r *http.Request, w http.ResponseWriter, session *gsessions.Session) error
- type GormStoreOptions
- type JSONSerializer
- type Options
- type RediStore
- func (s *RediStore) Get(r *http.Request, name string) (*gsessions.Session, error)
- func (s *RediStore) New(r *http.Request, name string) (*gsessions.Session, error)
- func (s *RediStore) Options(options Options)
- func (s *RediStore) RenewID(r *http.Request, w http.ResponseWriter, session *gsessions.Session) error
- func (s *RediStore) Save(r *http.Request, w http.ResponseWriter, session *gsessions.Session) error
- func (s *RediStore) SetMaxAge(v int)
- func (s *RediStore) SetMaxLength(l int)
- func (s *RediStore) SetSerializer(ss SessionSerializer)
- type Session
- type SessionSerializer
- type Store
Constants ¶
const (
DefaultKey = "github.com/MeloQi/sessions"
)
Variables ¶
This section is empty.
Functions ¶
func GorillaSessions ¶
func GorillaSessions(name string, store Store) gin.HandlerFunc
Types ¶
type GormStore ¶
type GormStore struct { Codecs []securecookie.Codec SessionOpts *gsessions.Options // contains filtered or unexported fields }
Store represent a gormstore
func NewGormStore ¶
New creates a new gormstore session
func NewGormStoreWithOptions ¶
func NewGormStoreWithOptions(db *gorm.DB, opts GormStoreOptions, keyPairs ...[]byte) *GormStore
NewOptions creates a new gormstore session with options
func (*GormStore) MaxAge ¶
MaxAge sets the maximum age for the store and the underlying cookie implementation. Individual sessions can be deleted by setting Options.MaxAge = -1 for that session.
func (*GormStore) MaxLength ¶
MaxLength restricts the maximum length of new sessions to l. If l is 0 there is no limit to the size of a session, use with caution. The default is 4096 (default for securecookie)
type GormStoreOptions ¶
Options for gormstore
type JSONSerializer ¶
type JSONSerializer struct{}
JSONSerializer encode the session map to JSON.
func (JSONSerializer) Deserialize ¶
func (s JSONSerializer) Deserialize(d []byte, ss *gsessions.Session) error
Deserialize back to map[string]interface{}
type Options ¶
type Options struct { Path string Domain string // MaxAge=0 means no 'Max-Age' attribute specified. // MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'. // MaxAge>0 means Max-Age attribute present and given in seconds. MaxAge int Secure bool HttpOnly bool }
Options stores configuration for a session or session store. Fields are a subset of http.Cookie fields.
type RediStore ¶
type RediStore struct { RedisClient *redis.Client Codecs []securecookie.Codec SessionOptions *gsessions.Options // default configuration DefaultMaxAge int // default Redis TTL for a MaxAge == 0 session // contains filtered or unexported fields }
RediStore stores sessions in a redis backend.
func NewRediStore ¶
func (*RediStore) Get ¶
Get returns a session for the given name after adding it to the registry.
See gorilla/sessions FilesystemStore.Get().
func (*RediStore) New ¶
New returns a session for the given name without adding it to the registry.
See gorilla/sessions FilesystemStore.New().
func (*RediStore) SetMaxAge ¶
SetMaxAge restricts the maximum age, in seconds, of the session record both in database and a browser. This is to change session storage configuration. If you want just to remove session use your session `s` object and change it's `Options.MaxAge` to -1, as specified in
http://godoc.org/github.com/gorilla/sessions#Options
Default is the one provided by this package value - `sessionExpire`. Set it to 0 for no restriction. Because we use `MaxAge` also in SecureCookie crypting algorithm you should use this function to change `MaxAge` value.
func (*RediStore) SetMaxLength ¶
SetMaxLength sets RediStore.maxLength if the `l` argument is greater or equal 0 maxLength restricts the maximum length of new sessions to l. If l is 0 there is no limit to the size of a session, use with caution. The default for a new RediStore is 4096. Redis allows for max. value sizes of up to 512MB (http://redis.io/topics/data-types) Default: 4096,
func (*RediStore) SetSerializer ¶
func (s *RediStore) SetSerializer(ss SessionSerializer)
SetSerializer sets the serializer
type Session ¶
type Session interface { // Get returns the session value associated to the given key. Get(key interface{}) interface{} // Set sets the session value associated to the given key. Set(key interface{}, val interface{}) // Delete removes the session value associated to the given key. Delete(key interface{}) // Clear deletes all values in the session. Clear() // AddFlash adds a flash message to the session. // A single variadic argument is accepted, and it is optional: it defines the flash key. // If not defined "_flash" is used by default. AddFlash(value interface{}, vars ...string) // Flashes returns a slice of flash messages from the session. // A single variadic argument is accepted, and it is optional: it defines the flash key. // If not defined "_flash" is used by default. Flashes(vars ...string) []interface{} // Options sets confuguration for a session. Options(Options) // Save saves all sessions used during the current request. Save() error RenewID() (string, error) ID() string SetMaxAge(maxAge int) Destroy() }
Wraps thinly gorilla-session methods. Session stores the values and optional configuration for a session.