Browse Source

return complete session when returning sessions

master
Lars Hoogestraat 1 month ago
parent
commit
664d7db4a3
2 changed files with 6 additions and 5 deletions
  1. +5
    -5
      session_provider.go
  2. +1
    -0
      session_service.go

+ 5
- 5
session_provider.go View File

@ -14,7 +14,7 @@ import (
type SessionProvider interface {
Create(sid string) *Session
Get(sid string) (*Session, error)
SessionIDsFromValues(key string, value interface{}) []string
SessionsFromValues(key string, value interface{}) []Session
Remove(sid string)
Clean(ticker *time.Ticker, timeoutAfter time.Duration)
}
@ -60,20 +60,20 @@ func (imp *InMemoryProvider) Get(sid string) (*Session, error) {
}
//SessionIDsFromValues receives all session ids from the map found with the key and value
func (imp *InMemoryProvider) SessionIDsFromValues(key string, value interface{}) []string {
func (imp *InMemoryProvider) SessionsFromValues(key string, value interface{}) []Session {
imp.mutex.RLock()
defer imp.mutex.RUnlock()
var ids []string
var sessions []Session
for _, s := range imp.sessions {
if s.values[key] == value {
ids = append(ids, s.SessionID())
sessions = append(sessions, *s)
}
}
return ids
return sessions
}
//Remove removes a session by the session identifier from the map


+ 1
- 0
session_service.go View File

@ -23,6 +23,7 @@ type SessionService struct {
SessionProvider SessionProvider
}
//Create creates the session for the request
func (sc SessionService) Create(rw http.ResponseWriter, r *http.Request) *Session {
sid := base64.StdEncoding.EncodeToString(randomSecureKey(64))


Loading…
Cancel
Save