Documentation ¶
Index ¶
- Constants
- Variables
- func LoadSession(data []byte, sess *Session) error
- type ID
- type Key
- type Manager
- func (m *Manager) Create(w http.ResponseWriter) (*Session, error)
- func (m *Manager) Delete(w http.ResponseWriter, r *http.Request)
- func (m *Manager) GetOrCreate(w http.ResponseWriter, r *http.Request) (*Session, error)
- func (m *Manager) Handler(next http.Handler) http.Handler
- func (m *Manager) Validate(value string) (ID, error)
- type Map
- type MemoryStore
- func (s *MemoryStore) DelSession(sid string) error
- func (s *MemoryStore) GetAllSessions() ([]*Session, error)
- func (s *MemoryStore) GetSession(sid string) (*Session, error)
- func (s *MemoryStore) HasSession(sid string) bool
- func (s *MemoryStore) SetSession(sid string, sess *Session) error
- func (s *MemoryStore) SyncSession(sess *Session) error
- type Options
- type Session
- type Store
Constants ¶
const DefaultSessionDuration = time.Hour
DefaultSessionDuration is the default duration for saving session data in the store. Most Store implementations will automatically delete saved session data after this time.
Variables ¶
var ( ErrSessionNotFound = errors.New("sessin not found or expired") ErrSessionExpired = errors.New("session expired") )
var ErrInvalidID = errors.New("Invalid Session ID")
ErrInvalidID is returned when an invalid session id is passed to ValidateID()
Functions ¶
func LoadSession ¶
Types ¶
type ID ¶
type ID string
ID represents a valid, digitally-signed session ID
const InvalidSessionID ID = ""
InvalidSessionID represents an empty, invalid session ID
func NewSessionID ¶
NewSessionID creates and returns a new digitally-signed session ID, using `signingKey` as the HMAC signing key. An error is returned only if there was an error generating random bytes for the session ID
func ValidateSessionID ¶
ValidateSessionID validates the `id` parameter using the `signingKey` and returns an error if invalid, or a SignedID if valid
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager ...
func (*Manager) Create ¶
func (m *Manager) Create(w http.ResponseWriter) (*Session, error)
Create ...
func (*Manager) Delete ¶
func (m *Manager) Delete(w http.ResponseWriter, r *http.Request)
Delete ...
func (*Manager) GetOrCreate ¶
GetOrCreate ...
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore represents an in-memory session store. This should be used only for testing and prototyping. Production systems should use a shared server store like redis
func NewMemoryStore ¶
func NewMemoryStore(sessionDuration time.Duration) *MemoryStore
NewMemoryStore constructs and returns a new MemoryStore
func (*MemoryStore) GetAllSessions ¶
func (s *MemoryStore) GetAllSessions() ([]*Session, error)
GetAllSessions ...
func (*MemoryStore) GetSession ¶
func (s *MemoryStore) GetSession(sid string) (*Session, error)
GetSession ...
func (*MemoryStore) SetSession ¶
func (s *MemoryStore) SetSession(sid string, sess *Session) error
SetSession ...
func (*MemoryStore) SyncSession ¶
func (s *MemoryStore) SyncSession(sess *Session) error
SyncSession ...
type Session ¶
type Session struct { ID string `json:"id"` Data Map `json:"data"` CreatedAt time.Time `json:"created"` ExpiresAt time.Time `json:"expires"` // contains filtered or unexported fields }
Session ...
func NewSession ¶
type Store ¶
type Store interface { GetSession(sid string) (*Session, error) SetSession(sid string, sess *Session) error HasSession(sid string) bool DelSession(sid string) error SyncSession(sess *Session) error GetAllSessions() ([]*Session, error) }
Store represents a session data store. This is an abstract interface that can be implemented against several different types of data stores. For example, session data could be stored in memory in a concurrent map, or more typically in a shared key/value server store like redis.