feat(session): error constants and variables

pull/10616/head
Leonardo Di Donato 2018-12-19 16:24:02 +01:00 committed by Leonardo Di Donato
parent 9d0ed9020c
commit 19eb016c5f
1 changed files with 16 additions and 1 deletions

View File

@ -6,6 +6,21 @@ import (
"time" "time"
) )
// ErrSessionNotFound is the error messages for a missing sessions.
const ErrSessionNotFound = "session not found"
// ErrSessionExpired is the error message for expired sessions.
const ErrSessionExpired = "session has expired"
var (
// OpFindSession represents the operation that looks for sessions.
OpFindSession = "FindSession"
// OpExpireSession represents the operation that expires sessions.
OpExpireSession = "ExpireSession"
// OpCreateSession represents the operation that creates a session for a given user.
OpCreateSession = "CreateSession"
)
// Session is a user session. // Session is a user session.
type Session struct { type Session struct {
// ID is only required for auditing purposes. // ID is only required for auditing purposes.
@ -20,7 +35,7 @@ type Session struct {
// Expired returns an error if the session is expired. // Expired returns an error if the session is expired.
func (s *Session) Expired() error { func (s *Session) Expired() error {
if time.Now().After(s.ExpiresAt) { if time.Now().After(s.ExpiresAt) {
return fmt.Errorf("session has expired") return fmt.Errorf(ErrSessionExpired)
} }
return nil return nil