keyring

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 1 Imported by: 0

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 ByKeyable

type ByKeyable []Keyable

func (ByKeyable) Len

func (k ByKeyable) Len() int

func (ByKeyable) Less

func (k ByKeyable) Less(i, j int) bool

func (ByKeyable) Swap

func (k ByKeyable) Swap(i, j int)

type Key

type Key string

func (Key) Key

func (k Key) Key() string

Key returns key so it can be used as a key a map[string].

func (Key) String

func (k Key) String() string

String formats the stringified key with additional contextual information

type Keyable

type Keyable interface {
	// The key as in a key-value pair
	Key() string

	// A stringified version of the key, for logging
	String() 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

func (kr *Keyring) CurrentUserKey() Keyable

CurrentUserKey returns the key set in the currentUserKey parameter of NewKeyring or nil.

func (*Keyring) Key

func (kr *Keyring) Key(name string) Keyable

Key returns the key by name (i.e., CtxKeyable.Key()) or nil.

func (*Keyring) SessionKey

func (kr *Keyring) SessionKey() Keyable

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.

Jump to

Keyboard shortcuts

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