123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- package user
- import "fmt"
- type Session interface {
-
- ID() string
-
- User() string
-
- GetAll() map[string]interface{}
-
- Get(key string) (interface{}, bool)
-
- Set(key string, value interface{})
-
- String() string
- }
- func NewDefaultSession(id string, user string) Session {
- return &DefaultSession{id, user, make(map[string]interface{})}
- }
- type DefaultSession struct {
- id string
- user string
- values map[string]interface{}
- }
- func (ds *DefaultSession) ID() string {
- return ds.id
- }
- func (ds *DefaultSession) User() string {
- return ds.user
- }
- func (ds *DefaultSession) GetAll() map[string]interface{} {
- return ds.values
- }
- func (ds *DefaultSession) Get(key string) (interface{}, bool) {
- ret, ok := ds.values[key]
- return ret, ok
- }
- func (ds *DefaultSession) Set(key string, value interface{}) {
- ds.values[key] = value
- }
- func (ds *DefaultSession) String() string {
- return fmt.Sprint("Session: ", ds.id, " (User:", ds.user, " Values:", ds.values, ")")
- }
|