Documentation ¶
Index ¶
- Constants
- Variables
- func DisableLog()
- func UseLogger(logger slog.Logger)
- type Sessions
- func (s *Sessions) DelSession(w http.ResponseWriter, r *http.Request) error
- func (s *Sessions) GetSession(r *http.Request) (*sessions.Session, error)
- func (s *Sessions) GetSessionUser(w http.ResponseWriter, r *http.Request) (*user.User, error)
- func (s *Sessions) GetSessionUserID(w http.ResponseWriter, r *http.Request) (string, error)
- func (s *Sessions) NewSession(w http.ResponseWriter, r *http.Request, userID string) error
Constants ¶
const ( // SessionMaxAge is the max age for a session in seconds. SessionMaxAge = 86400 // One day )
Variables ¶
var ( // ErrSessionNotFound is emitted when a session is not found in the // session store. ErrSessionNotFound = errors.New("session not found") )
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.
Types ¶
type Sessions ¶
type Sessions struct {
// contains filtered or unexported fields
}
Sessions manages politeiawww sessions.
func (*Sessions) DelSession ¶
DelSession removes the given session from the session store.
func (*Sessions) GetSession ¶
GetSession returns the Session for the session ID from the given http request cookie. If no session exists then a new session object is returned. Access IsNew on the session to check if it is an existing session or a new one. The new session will not have any sessions values set, such as user_id, and will not have been saved to the session store yet.
func (*Sessions) GetSessionUser ¶
GetSessionUser returns the User for the given session. A errSessionFound error is returned if a user session does not exist or has expired.
func (*Sessions) GetSessionUserID ¶
GetSessionUserID returns the user ID of the user for the given session. A ErrSessionNotFound error is returned if a user session does not exist or has expired.
func (*Sessions) NewSession ¶
NewSession creates a new session, adds it to the given http response session cookie, and saves it to the session store. If the http request already contains a session cookie then the session values will be updated and the session will be updated in the session store.