mirror of
https://github.com/alexedwards/scs.git
synced 2025-07-15 01:04:36 +02:00
Add Token() method
This commit is contained in:
12
data.go
12
data.go
@ -544,6 +544,18 @@ func (s *SessionManager) Deadline(ctx context.Context) time.Time {
|
|||||||
return sd.deadline
|
return sd.deadline
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Token returns the session token. Please note that this will return the
|
||||||
|
// empty string "" if it is called before the session has been committed to
|
||||||
|
// the store.
|
||||||
|
func (s *SessionManager) Token(ctx context.Context) string {
|
||||||
|
sd := s.getSessionDataFromContext(ctx)
|
||||||
|
|
||||||
|
sd.mu.Lock()
|
||||||
|
defer sd.mu.Unlock()
|
||||||
|
|
||||||
|
return sd.token
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SessionManager) addSessionDataToContext(ctx context.Context, sd *sessionData) context.Context {
|
func (s *SessionManager) addSessionDataToContext(ctx context.Context, sd *sessionData) context.Context {
|
||||||
return context.WithValue(ctx, s.contextKey, sd)
|
return context.WithValue(ctx, s.contextKey, sd)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user