Documentation ¶
Overview ¶
Package keyring defines how keys in a *http.Request.Context should behave and a way for storing and retrieving those keys for wider use in the application.
The main method for managing keys is through a Keyring, or a custom implementation of Keyringable.
Following https://medium.com/@matryer/context-keys-in-go-5312346a868d, context keys ought to be unexported by a package. This package cannot, in other words, provide default keys to be used in a context.Context.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Key ¶
type Key string
type Keyring ¶
type Keyring struct {
// contains filtered or unexported fields
}
Keyring stores CtxKeyables and cannot be mutated outside of a constructor.
func (*Keyring) CurrentUserKey ¶
CurrentUserKey returns the key set in the currentUserKey parameter of NewKeyring or nil.
func (*Keyring) SessionKey ¶
SessionKey returns the key set in the sessionKey parameter of NewKeyring or nil.
type Keyringable ¶
type Keyringable interface { CurrentUserKey() Keyable Key(name string) Keyable SessionKey() Keyable // contains filtered or unexported methods }
Something Keyringable because it stores arbitrary keys, accessible by a string name, and makes it convenient to grab a CurrentUserKey or SessionKey.
func NewKeyring ¶
func NewKeyring(sessionKey, currentUserKey Keyable, additional ...Keyable) Keyringable
NewKeyring constructs a Keyring from the given CtxKeyables. NewKeyring requires keys to be retrieved through CurrentUserKey() and SessionKey(), respectively. NewKeyring accepts an arbitrary number of other CtxKeyables, accessible through the Key method.
func WithKeyring ¶
func WithKeyring(parent Keyringable, additional ...Keyable) Keyringable
WithKeyring constructs a new Keyringable from the parent and adds additional CtxKeyables to the new Keyringable.