This repository has been archived on 2023-11-13. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
imagini/internal/session/session.go
2021-01-17 23:56:56 -05:00

39 lines
725 B
Go

package session
import (
"sync"
)
// Used to maintain a cache of user specific jwt secrets
// This will prevent DB lookups on every request
type SessionManager struct {
mutex sync.Mutex
values map[string]string
}
func NewMgr() *SessionManager {
return &SessionManager{}
}
func (sm *SessionManager) Set(key, value string) {
sm.mutex.Lock()
sm.values[key] = value
sm.mutex.Unlock()
}
func (sm *SessionManager) Get(key string) string {
sm.mutex.Lock()
defer sm.mutex.Unlock()
return sm.values[key]
}
func (sm *SessionManager) Delete(key string) {
sm.mutex.Lock()
defer sm.mutex.Unlock()
_, exists := sm.values[key]
if !exists {
return
}
delete(sm.values, key)
}