wolbodge/sessions/sessions.go
2025-03-22 14:27:28 +01:00

35 lines
667 B
Go

package sessions
import (
"errors"
"time"
)
type Session struct {
Id string
Description string
CreatedAt time.Time
}
func (s *Session) ExistsFor() time.Duration {
return time.Now().Sub(s.CreatedAt)
}
var (
ErrUnknownSession = errors.New("unknown session")
)
type Storage interface {
// Check if the storage contains any sessions.
HasSessions() (bool, error)
// List all sessions.
GetSessions() ([]Session, error)
// Start a new session.
StartSession(description string, createdAt time.Time) (Session, error)
// End an old session.
// Should return [ErrUnknownSession] if the session couldn't be found.
EndSession(id string) error
}