Documentation
¶
Overview ¶
Package session presents a lazy context that manages session state with native key rotation support.
Index ¶
- Constants
- func Address(ctx context.Context) string
- func Expires(ctx context.Context) time.Time
- func ID(ctx context.Context) string
- func New(withOptions ...Option) (func(http.Handler) http.Handler, error)
- func Read(ctx context.Context, view func(Session) error) (err error)
- func Role(ctx context.Context) string
- func SetRole(ctx context.Context, name string) error
- func SetUserID(ctx context.Context, id string) error
- func SetValue(ctx context.Context, key string, value any) error
- func Sign(secret *secrets.Secret, b []byte) []byte
- func TraceID(ctx context.Context) string
- func UserID(ctx context.Context) string
- func Validate(secret *secrets.Secret, b []byte) bool
- func Value(ctx context.Context, key string) any
- func Write(ctx context.Context, update func(Session) error) (err error)
- type CookieCodec
- type Error
- type Factory
- type Option
- func WithCookieCodec(c CookieCodec) Option
- func WithDefaultCookieCodec() Option
- func WithDefaultExpiry() Option
- func WithDefaultFactory() Option
- func WithDefaultName() Option
- func WithDefaultRotationContext() Option
- func WithDefaultTokenizer() Option
- func WithExpiry(d time.Duration) Option
- func WithFactory(f Factory) Option
- func WithName(name string) Option
- func WithRotationContext(ctx context.Context) Option
- func WithTokenizer(t Tokenizer) Option
- type Session
- type SlogHandler
- type Tokenizer
Constants ¶
View Source
const MaximumCookieSize = 4096
A browser should be able to accept at least 300 cookies with a maximum size of 4096 bytes, as stipulated by RFC 2109 (#6.3), RFC 2965 (#5.3), and RFC 6265.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CookieCodec ¶
type CookieCodec interface { WriteCookie(http.ResponseWriter, string, time.Time) error ReadCookie(*http.Request) string }
func NewStrictCookieCodec ¶
func NewStrictCookieCodec(name, path string) CookieCodec
type Option ¶
type Option func(*options) error
func WithCookieCodec ¶
func WithCookieCodec(c CookieCodec) Option
func WithDefaultCookieCodec ¶
func WithDefaultCookieCodec() Option
func WithDefaultExpiry ¶
func WithDefaultExpiry() Option
func WithDefaultFactory ¶
func WithDefaultFactory() Option
func WithDefaultName ¶
func WithDefaultName() Option
func WithDefaultRotationContext ¶
func WithDefaultRotationContext() Option
func WithDefaultTokenizer ¶
func WithDefaultTokenizer() Option
func WithExpiry ¶
func WithFactory ¶
func WithRotationContext ¶
func WithTokenizer ¶
type Session ¶
type Session interface { ID() string TraceID() string Address() string UserID() string SetUserID(string) Role() string SetRole(string) Expires() time.Time IsExpired() bool IsNew() bool Get(string) any Int(string) int Int64(string) int64 Float32(string) float32 Float64(string) float64 Set(string, any) Reset() }
type SlogHandler ¶
type SlogHandler struct {
// contains filtered or unexported fields
}
func NewSlogHandler ¶
func NewSlogHandler(h slog.Handler) *SlogHandler
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package secrets provides a synchronizable set of keys backed by a key-value store.
|
Package secrets provides a synchronizable set of keys backed by a key-value store. |
Package token provides [Authority]s that issue and validate access tokens.
|
Package token provides [Authority]s that issue and validate access tokens. |
gorilla
Package gorilla couples [securecookie.SecureCookie] token encoder with [secrets.Rotation].
|
Package gorilla couples [securecookie.SecureCookie] token encoder with [secrets.Rotation]. |
jwt
Package jwt provides [token.Authority] with secure JSON Web Tokens issuer defaults.
|
Package jwt provides [token.Authority] with secure JSON Web Tokens issuer defaults. |
Click to show internal directories.
Click to hide internal directories.