Documentation ¶
Overview ¶
Package sessions contains a Session type used to track session cookies in HTTP responses.
Each session will have a unique selector and session ID, be attached to a single user account, and can be persistent or session only.
This package should be not be uses without seshandler which manages sessions for a server.
Index ¶
- type Session
- func (s *Session) AddError(err ...interface{})
- func (s *Session) AddMessage(msg ...interface{})
- func (s *Session) CookieValue() string
- func (s *Session) Destroy()
- func (s *Session) EncryptedUsername() string
- func (s *Session) Equals(other *Session, hash func(string) string) bool
- func (s *Session) ExpireTime() time.Time
- func (s *Session) Flashes() ([]interface{}, []interface{})
- func (s *Session) HashPayload() string
- func (s *Session) IsDestroyed() bool
- func (s *Session) IsExpired() bool
- func (s *Session) IsPersistent() bool
- func (s *Session) IsUserLoggedIn() bool
- func (s *Session) IsValid() bool
- func (s *Session) LogUserIn(username, encryptedUsername string) error
- func (s *Session) LogUserOut()
- func (s *Session) MarkSessionExpired()
- func (s *Session) SelectorID() string
- func (s *Session) SessionCookie() *http.Cookie
- func (s *Session) SessionID() string
- func (s *Session) TextToValues(text string) error
- func (s *Session) UpdateExpireTime(maxLifetime time.Duration)
- func (s *Session) Username() string
- func (s *Session) ValuesAsText() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session type represents an HTTP session.
func NewSession ¶
func NewSession(selectorID, sessionID, username, encryptedUsername, sessionCookieName string, maxLifetime time.Duration) *Session
NewSession creates a new session with the given information
func (*Session) AddError ¶
func (s *Session) AddError(err ...interface{})
AddError adds an error to the session flashes
func (*Session) AddMessage ¶
func (s *Session) AddMessage(msg ...interface{})
AddMessage adds an error to the session flashes
func (*Session) CookieValue ¶
CookieValue returns the value of the cookie to send with the response
func (*Session) EncryptedUsername ¶
EncryptedUsername returns the username of the account to which the session is associated.
func (*Session) ExpireTime ¶
ExpireTime returns the time that the session will expire.
func (*Session) Flashes ¶
func (s *Session) Flashes() ([]interface{}, []interface{})
Flashes gets and deletes the flash messages.
func (*Session) HashPayload ¶
HashPayload returns the string related to the session to be hashed.
func (*Session) IsDestroyed ¶
IsDestroyed returns whether the session has been destroyed
func (*Session) IsPersistent ¶
IsPersistent returns whether the session is a persistent one.
func (*Session) IsUserLoggedIn ¶
IsUserLoggedIn returns true if the user is logged in
func (*Session) IsValid ¶
IsValid returns whether the session is valid A session is valid if it is neither destroyed nor expired.
func (*Session) LogUserIn ¶
LogUserIn logs a user into a session. It returns a non-nil error if there is already a user logged into that session.
func (*Session) LogUserOut ¶
func (s *Session) LogUserOut()
LogUserOut logs a user out of a session.
func (*Session) MarkSessionExpired ¶
func (s *Session) MarkSessionExpired()
MarkSessionExpired marks the session expired.
func (*Session) SelectorID ¶
SelectorID returns the session's selector ID
func (*Session) SessionCookie ¶
SessionCookie builds a cookie from the Session struct
func (*Session) TextToValues ¶
TextToValues converts the string to a values map for the session. It returns an error if the string cannot be converted.
func (*Session) UpdateExpireTime ¶
UpdateExpireTime updates the time that the session expires
func (*Session) Username ¶
Username returns the username of the account to which the session is associated.
func (*Session) ValuesAsText ¶
ValuesAsText converts the values into text for storage in a database.