Documentation ¶
Overview ¶
Package cookie provides middleware for working with device, session and user session cookies.
Index ¶
- func DeviceUIDFromContext(ctx context.Context) ksuid.KSUID
- func SessionUIDFromContext(ctx context.Context) ksuid.KSUID
- func UserSessionUIDFromContext(ctx context.Context) ksuid.KSUID
- type Middleware
- func (m *Middleware) DeviceUID(next http.Handler) http.Handler
- func (m *Middleware) MustNewUID() ksuid.KSUID
- func (m *Middleware) Register(s *server.Server)
- func (m *Middleware) SessionUID(next http.Handler) http.Handler
- func (m *Middleware) SetDeviceUID(w http.ResponseWriter, value ksuid.KSUID)
- func (m *Middleware) SetUserSessionUID(w http.ResponseWriter, value ksuid.KSUID, maxAge int)
- func (m *Middleware) UnsetUserSessionUID(w http.ResponseWriter)
- func (m *Middleware) UserSessionUID(next http.Handler) http.Handler
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeviceUIDFromContext ¶
DeviceUIDFromContext returns the device UID from a request context, or returns ksuid.Nil if there is no device UID present.
func SessionUIDFromContext ¶
SessionUIDFromContext returns the session UID from a request context, or returns ksuid.Nil if there is no 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.