nano-run/server/ui/sessions.go
Alexander Baryshnikov 68c0c63a9f add admin UI
2020-10-01 21:09:40 +08:00

38 lines
670 B
Go

package ui
import "sync"
const sessionCookie = "session-id"
type Session interface {
Login() string
Valid() bool
}
type SessionStorage interface {
Save(sessionID string, session Session)
Get(sessionID string) (Session, bool)
Delete(sessionID string)
}
type memorySessions struct {
store sync.Map
}
func (ms *memorySessions) Save(sessionID string, session Session) {
ms.store.Store(sessionID, session)
}
func (ms *memorySessions) Get(sessionID string) (Session, bool) {
v, ok := ms.store.Load(sessionID)
if !ok {
return nil, ok
}
s, ok := v.(Session)
return s, ok
}
func (ms *memorySessions) Delete(sessionID string) {
ms.store.Delete(sessionID)
}