ginsess

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2021 License: MIT Imports: 9 Imported by: 0

README

gin-sess

gin sessions

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(opts ...OptionFunc) gin.HandlerFunc

Middleware .

Types

type CookieStore

type CookieStore struct {
}

CookieStore a store use cookies

func (*CookieStore) Load added in v1.0.2

func (s *CookieStore) Load(sess *Session) error

Load load data from cookie.

func (*CookieStore) Save added in v1.0.2

func (s *CookieStore) Save(sess *Session) error

Save save change to cookie.

type Option

type Option struct {
	// contains filtered or unexported fields
}

Option .

type OptionFunc

type OptionFunc func(*Option)

OptionFunc .

func SetAlwaysRefresh

func SetAlwaysRefresh(ok bool) OptionFunc

func SetCookieDomain added in v1.0.2

func SetCookieDomain(domain string) OptionFunc

SetCookieDomain .

func SetCookieHttpOnly added in v1.0.2

func SetCookieHttpOnly(yes bool) OptionFunc

SetCookieHttpOnly .

func SetCookieName

func SetCookieName(name string) OptionFunc

SetCookieName .

func SetCookiePath added in v1.0.2

func SetCookiePath(path string) OptionFunc

SetCookiePath .

func SetExpriedTime

func SetExpriedTime(dur time.Duration) OptionFunc

func SetStore

func SetStore(store Store) OptionFunc

SetStore .

type RedisStore

type RedisStore struct {
	// contains filtered or unexported fields
}

RedisStore a store use cookies

func (*RedisStore) Load added in v1.0.2

func (s *RedisStore) Load(sess *Session) error

Load load data from redis.

func (*RedisStore) Save added in v1.0.2

func (s *RedisStore) Save(sess *Session) error

Save save change to redis.

type Session

type Session struct {
	// contains filtered or unexported fields
}

func GetSession

func GetSession(c *gin.Context) (*Session, error)

GetSession get session from gin context

func Must added in v1.0.2

func Must(c *Session, err error) *Session

Must get session before GetSession function. Panic occurs when session instance is not found.

func (*Session) DefaultBool

func (sess *Session) DefaultBool(key string, def bool) bool

DefaultBool get value by key. if not exists well be returns default value.

func (*Session) DefaultDuration added in v1.0.2

func (sess *Session) DefaultDuration(key string, def time.Duration) time.Duration

DefaultDuration get value by key. if not exists well be returns default value.

func (*Session) DefaultFloat32

func (sess *Session) DefaultFloat32(key string, def float32) float32

DefaultFloat32 get value by key. if not exists well be returns default value.

func (*Session) DefaultFloat64

func (sess *Session) DefaultFloat64(key string, def float64) float64

DefaultFloat64 get value by key. if not exists well be returns default value.

func (*Session) DefaultInt

func (sess *Session) DefaultInt(key string, def int) int

DefaultInt get value by key. if not exists well be returns default value.

func (*Session) DefaultIntSlice

func (sess *Session) DefaultIntSlice(key string, def []int) []int

DefaultIntSlice get value by key. if not exists well be returns default value.

func (*Session) DefaultString

func (sess *Session) DefaultString(key string, def string) string

DefaultString get value by key. if not exists well be returns default value.

func (*Session) DefaultStringMap added in v1.0.2

func (sess *Session) DefaultStringMap(key string, def map[string]interface{}) map[string]interface{}

DefaultStringMap get value by key. if not exists well be returns default value.

func (*Session) DefaultStringMapString added in v1.0.2

func (sess *Session) DefaultStringMapString(key string, def map[string]string) map[string]string

DefaultStringMapString get value by key. if not exists well be returns default value.

func (*Session) DefaultStringSlice added in v1.0.2

func (sess *Session) DefaultStringSlice(key string, def []string) []string

DefaultStringSlice get value by key. if not exists well be returns default value.

func (*Session) DefaultTime added in v1.0.2

func (sess *Session) DefaultTime(key string, def time.Time) time.Time

DefaultTime get value by key. if not exists well be returns default value.

func (*Session) Get

func (sess *Session) Get(key string) (interface{}, bool)

Get get value from store

func (*Session) GetBool

func (sess *Session) GetBool(key string) (bool, bool)

GetBool get value and exists

func (*Session) GetDuration added in v1.0.2

func (sess *Session) GetDuration(key string) (time.Duration, bool)

GetDuration get value and exists

func (*Session) GetFloat32

func (sess *Session) GetFloat32(key string) (float32, bool)

GetFloat32 get value and exists

func (*Session) GetFloat64

func (sess *Session) GetFloat64(key string) (float64, bool)

GetFloat64 get value and exists

func (*Session) GetInt

func (sess *Session) GetInt(key string) (int, bool)

GetInt get value and exists

func (*Session) GetIntSlice

func (sess *Session) GetIntSlice(key string) ([]int, bool)

GetIntSlice get value and exists

func (*Session) GetString

func (sess *Session) GetString(key string) (string, bool)

GetString get value by string.

func (*Session) GetStringMap added in v1.0.2

func (sess *Session) GetStringMap(key string) (map[string]interface{}, bool)

GetStringMap get value and exists

func (*Session) GetStringMapString added in v1.0.2

func (sess *Session) GetStringMapString(key string) (map[string]string, bool)

GetStringMapString get value and exists

func (*Session) GetStringSlice added in v1.0.2

func (sess *Session) GetStringSlice(key string) ([]string, bool)

GetStringSlice get value and exists

func (*Session) GetTime added in v1.0.2

func (sess *Session) GetTime(key string) (time.Time, bool)

GetTime get value and exists

func (*Session) IsSet added in v1.0.2

func (sess *Session) IsSet(key string) bool

func (*Session) Load added in v1.0.2

func (sess *Session) Load() error

func (*Session) MustBool added in v1.0.2

func (sess *Session) MustBool(key string) bool

MustBool get value by key. if exists well be returns value, if not exists well return false.

func (*Session) MustDuration added in v1.0.2

func (sess *Session) MustDuration(key string) time.Duration

MustDuration get value by key.

func (*Session) MustFloat32 added in v1.0.2

func (sess *Session) MustFloat32(key string) float32

MustFloat32 get value by key. if exists well be returns value, if not exists well return false.

func (*Session) MustFloat64 added in v1.0.2

func (sess *Session) MustFloat64(key string) float64

MustFloat64 get value by key. if exists well be returns value, if not exists well return false.

func (*Session) MustInt added in v1.0.2

func (sess *Session) MustInt(key string) int

MustInt get value by key. if exists well be returns value, if not exists well return false.

func (*Session) MustIntSlice added in v1.0.2

func (sess *Session) MustIntSlice(key string) []int

MustIntSlice get value by key.

func (*Session) MustString added in v1.0.2

func (sess *Session) MustString(key string) string

MustString get value by key. if exists well be returns string value, if not exists well return empty string.

func (*Session) MustStringMap added in v1.0.2

func (sess *Session) MustStringMap(key string) map[string]interface{}

MustStringMap get value by key.

func (*Session) MustStringMapString added in v1.0.2

func (sess *Session) MustStringMapString(key string) map[string]string

MustStringMapString get value by key.

func (*Session) MustStringSlice added in v1.0.2

func (sess *Session) MustStringSlice(key string) []string

MustStringSlice get value by key.

func (*Session) MustTime added in v1.0.2

func (sess *Session) MustTime(key string) time.Time

MustTime get value by key.

func (*Session) Save added in v1.0.2

func (sess *Session) Save() error

func (*Session) Set

func (sess *Session) Set(key string, val interface{})

Set set value from store

type Store

type Store interface {
	Save(*Session) error
	Load(*Session) error
}

Store .

func NewCookieStore added in v1.0.2

func NewCookieStore() Store

NewCookieStore create a store with redis instance.

func NewRedisStore

func NewRedisStore(client *redis.Client) Store

NewRedisStore create a store with redis instance.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL