Documentation
¶
Overview ¶
Package sessions stores per-user data in an encrypted cookie:
ternApp(kit.WithPlugins(sessions.New(os.Getenv("SESSION_SECRET"))))
func Load(ctx *kit.Ctx) (Data, error) {
s := sessions.Get(ctx)
user := s.GetString("user")
notice := s.Flash("notice") // read once
...
}
Values are JSON-encoded and sealed with AES-GCM, so users can neither read nor change them. Keep sessions small: cookies are limited to about 4 KB. Changes are saved automatically.
Index ¶
- type Option
- type Plugin
- type Session
- func (s *Session) AddFlash(key, message string) error
- func (s *Session) Clear()
- func (s *Session) Delete(key string) error
- func (s *Session) Flash(key string) string
- func (s *Session) GetString(key string) string
- func (s *Session) Set(key string, v any) error
- func (s *Session) Value(key string, dst any) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Plugin)
Option configures the plugin.
func OldSecrets ¶
OldSecrets keeps sessions sealed with previous secrets readable, so the secret can be rotated without signing everyone out.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin loads and saves sessions. Create it with New.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is one user's session data.
func Get ¶
Get returns the request's session. It panics if the sessions plugin is not installed, which is a programming error.
func (*Session) Clear ¶
func (s *Session) Clear()
Clear removes everything, for example when signing out.