cookie

package
v0.0.0-...-fc4206c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package cookie provides middleware for working with device, session and user session cookies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeviceUIDFromContext

func DeviceUIDFromContext(ctx context.Context) ksuid.KSUID

DeviceUIDFromContext returns the device UID from a request context, or returns ksuid.Nil if there is no device UID present.

func SessionUIDFromContext

func SessionUIDFromContext(ctx context.Context) ksuid.KSUID

SessionUIDFromContext returns the session UID from a request context, or returns ksuid.Nil if there is no session UID present.

func UserSessionUIDFromContext

func UserSessionUIDFromContext(ctx context.Context) ksuid.KSUID

UserSessionUIDFromContext returns the user session UID from a request context, or returns ksuid.Nil if there is no user session UID present.

Types

type Middleware

type Middleware struct {
	// contains filtered or unexported fields
}

Middleware is cookie middleware. Use NewMiddleware to create a new Middleware.

func NewMiddleware

func NewMiddleware(opts ...Option) *Middleware

NewMiddleware returns new cookie middleware.

Options can be used to override the default options that work with: a "suid" (session) cookie that expires when the browser is closed, a "duid" (device) cookie that expires after 180 days, a "usuid" (user session) cookie.

Note that the cookie middleware doesn't prevent (malicious) clients from sending cookies after they have expired.

func (*Middleware) DeviceUID

func (m *Middleware) DeviceUID(next http.Handler) http.Handler

DeviceUID is a middleware that reads device UID cookies from requests, or generates a new device UID.

func (*Middleware) MustNewUID

func (m *Middleware) MustNewUID() ksuid.KSUID

MustNewUID returns a new KSUID or panics if it's unable to.

func (*Middleware) Register

func (m *Middleware) Register(s *server.Server)

Register registers the middleware to a backbone server.

func (*Middleware) SessionUID

func (m *Middleware) SessionUID(next http.Handler) http.Handler

SessionUID is a middleware that reads session UID cookies from requests, or generates a new session UID.

func (*Middleware) SetDeviceUID

func (m *Middleware) SetDeviceUID(w http.ResponseWriter, value ksuid.KSUID)

SetDeviceUID sets (replaces) the user device UID cookie.

func (*Middleware) SetUserSessionUID

func (m *Middleware) SetUserSessionUID(w http.ResponseWriter, value ksuid.KSUID, maxAge int)

SetUserSessionUID sets the user session UID cookie, with expiry after maxAge.

func (*Middleware) UnsetUserSessionUID

func (m *Middleware) UnsetUserSessionUID(w http.ResponseWriter)

UnsetUserSessionUID unsets the user session UID cookie.

func (*Middleware) UserSessionUID

func (m *Middleware) UserSessionUID(next http.Handler) http.Handler

UserSessionUID is a middleware that reads the user session UID cookie from requests.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is an option for the cookie middleware.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL