45 lines
922 B
Go
45 lines
922 B
Go
package stores
|
|
|
|
import (
|
|
"errors"
|
|
"strconv"
|
|
)
|
|
|
|
type Session struct {
|
|
Token string
|
|
UserID uint
|
|
MandantId uint
|
|
}
|
|
|
|
func (s *Session) Deserialize(t string, m map[string]string) (*Session, error) {
|
|
userid, err := strconv.Atoi(m["userid"])
|
|
if err != nil {
|
|
return nil, errors.New("Userid from cache not an int")
|
|
}
|
|
|
|
mandantid, err := strconv.Atoi(m["mandantid"])
|
|
if err != nil {
|
|
return nil, errors.New("Mandantid from cache not an int")
|
|
}
|
|
|
|
s.Token = t
|
|
s.UserID = uint(userid)
|
|
s.MandantId = uint(mandantid)
|
|
|
|
return s, nil
|
|
}
|
|
|
|
func (s *Session) Serialize() map[string]string {
|
|
m := make(map[string]string)
|
|
m["userid"] = strconv.Itoa(int(s.UserID))
|
|
m["mandantid"] = strconv.Itoa(int(s.MandantId))
|
|
return m
|
|
}
|
|
|
|
type SessionStore interface {
|
|
AddSession(s *Session)
|
|
GetSessionFromToken(token string) (*Session, error)
|
|
RemoveSession(token string)
|
|
SetMandantInSession(token string, mandantId uint) error
|
|
}
|