Documentation
¶
Index ¶
- Constants
- Variables
- type CookieStore
- type MemoryOption
- type MemoryStore
- type PostgresOptions
- type PostgresStore
- func (s *PostgresStore) Cleanup(ctx context.Context) error
- func (s *PostgresStore) Clear(w http.ResponseWriter, session *Session)
- func (s *PostgresStore) EnsureTable(ctx context.Context) error
- func (s *PostgresStore) Get(r *http.Request) (*Session, error)
- func (s *PostgresStore) Save(w http.ResponseWriter, session *Session) error
- type RedisOptions
- type RedisStore
- type Session
- type Store
Constants ¶
const DefaultPostgresTable = "bebo_sessions"
Variables ¶
var ( // ErrInvalidCookie indicates an invalid or tampered session cookie. ErrInvalidCookie = errors.New("invalid session cookie") )
Functions ¶
This section is empty.
Types ¶
type CookieStore ¶
type CookieStore struct {
Name string
Keys [][]byte
Path string
MaxAge time.Duration
Secure bool
HTTPOnly bool
SameSite http.SameSite
}
CookieStore stores sessions in a signed cookie.
func NewCookieStore ¶
func NewCookieStore(name string, key []byte, oldKeys ...[]byte) *CookieStore
NewCookieStore creates a cookie store with key rotation support.
func (*CookieStore) Clear ¶
func (s *CookieStore) Clear(w http.ResponseWriter, session *Session)
Clear expires the session cookie.
func (*CookieStore) Get ¶
func (s *CookieStore) Get(r *http.Request) (*Session, error)
Get loads a session from the request.
func (*CookieStore) Save ¶
func (s *CookieStore) Save(w http.ResponseWriter, session *Session) error
Save writes the session cookie.
type MemoryOption ¶
type MemoryOption func(*MemoryStore)
MemoryOption configures a MemoryStore.
func WithSessionHTTPOnly ¶
func WithSessionHTTPOnly(enabled bool) MemoryOption
WithSessionHTTPOnly sets the session cookie HttpOnly flag.
func WithSessionPath ¶
func WithSessionPath(path string) MemoryOption
WithSessionPath sets the session cookie path.
func WithSessionSameSite ¶
func WithSessionSameSite(mode http.SameSite) MemoryOption
WithSessionSameSite sets the session cookie SameSite flag.
func WithSessionSecure ¶
func WithSessionSecure(enabled bool) MemoryOption
WithSessionSecure sets the session cookie Secure flag.
type MemoryStore ¶
type MemoryStore struct {
Name string
TTL time.Duration
Path string
Secure bool
HTTPOnly bool
SameSite http.SameSite
// contains filtered or unexported fields
}
MemoryStore stores sessions in memory and uses a session ID cookie.
func NewMemoryStore ¶
func NewMemoryStore(name string, ttl time.Duration, options ...MemoryOption) *MemoryStore
NewMemoryStore creates an in-memory store.
func (*MemoryStore) Clear ¶
func (s *MemoryStore) Clear(w http.ResponseWriter, session *Session)
Clear removes a session.
func (*MemoryStore) Get ¶
func (s *MemoryStore) Get(r *http.Request) (*Session, error)
Get loads a session from the request.
func (*MemoryStore) Save ¶
func (s *MemoryStore) Save(w http.ResponseWriter, session *Session) error
Save persists a session.
type PostgresOptions ¶
type PostgresOptions struct {
DisableDefaults bool
DB *sql.DB
Name string
Table string
TTL time.Duration
Timeout time.Duration
Path string
Secure bool
HTTPOnly bool
SameSite http.SameSite
}
PostgresOptions configures a Postgres store.
type PostgresStore ¶
type PostgresStore struct {
DB *sql.DB
Name string
Table string
TTL time.Duration
Timeout time.Duration
Path string
Secure bool
HTTPOnly bool
SameSite http.SameSite
// contains filtered or unexported fields
}
PostgresStore stores sessions in PostgreSQL using a session ID cookie.
func NewPostgresStore ¶
func NewPostgresStore(options PostgresOptions) (*PostgresStore, error)
NewPostgresStore builds a Postgres-backed store.
func (*PostgresStore) Cleanup ¶
func (s *PostgresStore) Cleanup(ctx context.Context) error
Cleanup removes expired sessions.
func (*PostgresStore) Clear ¶
func (s *PostgresStore) Clear(w http.ResponseWriter, session *Session)
Clear removes a session.
func (*PostgresStore) EnsureTable ¶
func (s *PostgresStore) EnsureTable(ctx context.Context) error
EnsureTable creates the session table if it does not exist.
func (*PostgresStore) Get ¶
func (s *PostgresStore) Get(r *http.Request) (*Session, error)
Get loads a session from the request.
func (*PostgresStore) Save ¶
func (s *PostgresStore) Save(w http.ResponseWriter, session *Session) error
Save persists a session.
type RedisOptions ¶
type RedisOptions struct {
DisableDefaults bool
Name string
Network string
Address string
Username string
Password string
DB int
TTL time.Duration
Prefix string
DialTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
Path string
Secure bool
HTTPOnly bool
SameSite http.SameSite
}
RedisOptions configures a Redis store.
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
RedisStore stores sessions in Redis using a session ID cookie.
func NewRedisStore ¶
func NewRedisStore(options RedisOptions) *RedisStore
NewRedisStore creates a Redis-backed session store.
func (*RedisStore) Clear ¶
func (s *RedisStore) Clear(w http.ResponseWriter, session *Session)
Clear removes a session.
func (*RedisStore) Get ¶
func (s *RedisStore) Get(r *http.Request) (*Session, error)
Get loads a session from the request.
func (*RedisStore) Save ¶
func (s *RedisStore) Save(w http.ResponseWriter, session *Session) error
Save persists a session.
type Session ¶
type Session struct {
ID string
Values map[string]string
// contains filtered or unexported fields
}
Session represents session data.
func (*Session) Clear ¶
func (s *Session) Clear(w http.ResponseWriter)
Clear clears the session from the configured store.