sessions

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Int = iota
	Int64
	Float32
	Float64
	String
	Bool
)

Variables

View Source
var (
	ERR_KEY_EXIST         = errors.New("key exist")
	ERR_KEY_NOT_EXIST     = errors.New("key not exist")
	ERR_KEY_INVALID_TYPE  = errors.New("key invalid type")
	ERR_KEY_INVALID_VALUE = errors.New("key invalid value")
)

Functions

func ValueTypesConvertNameToType

func ValueTypesConvertNameToType(t string) (uint8, error)

Types

type Backend

type Backend interface {
	SetExpiriesSecond(int64)
	Get(SessionID) (raw []byte, exist bool, err error)
	Save(SessionID, []byte) error
}

func NewBackendRam

func NewBackendRam(isSnapshot bool, snapshotFile string) Backend

type RamStorage

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

func (*RamStorage) Get

func (r *RamStorage) Get(sessID SessionID) ([]byte, bool, error)

func (*RamStorage) Save

func (r *RamStorage) Save(sessID SessionID, raw []byte) (err error)

func (*RamStorage) SetExpiriesSecond

func (r *RamStorage) SetExpiriesSecond(exp int64)

type Session

type Session interface {
	Get(tok *token.Token) (*Value, error)
	Save(tok *token.Token, val *Value) error
}

func NewSession

func NewSession(expirions int64, storage Backend) Session

type SessionDefault

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

func (*SessionDefault) Get

func (s *SessionDefault) Get(tok *token.Token) (*Value, error)

func (*SessionDefault) Save

func (s *SessionDefault) Save(tok *token.Token, val *Value) error

type SessionID

type SessionID string

type Value

type Value struct {
	S map[string]*ValueTypes `json:"val"`
	// contains filtered or unexported fields
}

func (*Value) Delete

func (b *Value) Delete(key string) (ok bool, err error)

func (*Value) GetBool

func (b *Value) GetBool(key string) (val bool, exist bool, err error)

func (*Value) GetFloat32

func (b *Value) GetFloat32(key string) (val float32, exist bool, err error)

func (*Value) GetFloat64

func (b *Value) GetFloat64(key string) (val float64, exist bool, err error)

func (*Value) GetInt

func (b *Value) GetInt(key string) (val int, exist bool, err error)

func (*Value) GetInt64

func (b *Value) GetInt64(key string) (val int64, exist bool, err error)

func (*Value) GetString

func (b *Value) GetString(key string) (val string, exist bool, err error)

func (*Value) IsKeyExist

func (b *Value) IsKeyExist(key string) bool

func (*Value) Iterator

func (b *Value) Iterator(fn func(string, *ValueTypes, error))

func (Value) MarshalEasyJSON

func (v Value) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Value) MarshalJSON

func (v Value) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Value) SetBool

func (b *Value) SetBool(key string, val bool) (err error)

func (*Value) SetFloat32

func (b *Value) SetFloat32(key string, val float32) (err error)

func (*Value) SetFloat64

func (b *Value) SetFloat64(key string, val float64) (err error)

func (*Value) SetInt

func (b *Value) SetInt(key string, val int) (err error)

func (*Value) SetInt64

func (b *Value) SetInt64(key string, val int64) (err error)

func (*Value) SetString

func (b *Value) SetString(key string, val string) (err error)

func (*Value) UnmarshalEasyJSON

func (v *Value) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Value) UnmarshalJSON

func (v *Value) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

func (*Value) UpBool

func (b *Value) UpBool(key string, val bool) (err error)

func (*Value) UpFloat32

func (b *Value) UpFloat32(key string, val float32) (err error)

func (*Value) UpFloat64

func (b *Value) UpFloat64(key string, val float64) (err error)

func (*Value) UpInt

func (b *Value) UpInt(key string, val int) (err error)

func (*Value) UpInt64

func (b *Value) UpInt64(key string, val int64) (err error)

func (*Value) UpString

func (b *Value) UpString(key string, val string) (err error)

type ValueTypes

type ValueTypes struct {
	Type  uint8       `json:"t"`
	Value interface{} `json:"d"`
}

func (*ValueTypes) Cast

func (b *ValueTypes) Cast() (*ValueTypes, error)

Jump to

Keyboard shortcuts

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