handlers

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 19, 2020 License: MIT Imports: 4 Imported by: 5

README

Handlers

This package contains handlers to forward values coming from a request header or a cookie, to a request context.

The mapping is done using enumeration of possible header and cookie keys, and their corresponding context key.

Usage

  • Read a header from a request and add its value to the underlying request context:
    // Access token
    handler := handlers.CheckHeader(h, handlers.UserAccessHeaderKey)

    // Locale
    handler := handlers.CheckHeader(h, handlers.LocaleHeaderKey)

    // CollectionID
    handler := handlers.CheckHeader(h, handlers.CollectionIDHeaderKey)
  • Read a cookie and add its value to the output request context:
    // Access token
    handler := handlers.CheckCookie(h, handlers.UserAccessCookieKey)

    // Locale
    handler := handlers.CheckCookie(h, handlers.LocaleCookieKey)

    // CollectionID
    handler := handlers.CheckCookie(h, handlers.CollectionIDCookieKey)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckCookie

func CheckCookie(h http.Handler, cookieKey CookieKey) http.Handler

CheckCookie is a wrapper which adds a cookie value to context if one does not yet exist

func CheckCookieMiddleware added in v1.0.3

func CheckCookieMiddleware(cookieKey CookieKey) func(http.Handler) http.Handler

CheckCookieMiddleware returns a CheckCookie function for the provided cookie key as a middleware function (alice middleware Constructor, ie. func(http.Handler) -> (http.Handler))

func CheckHeader

func CheckHeader(h http.Handler, headerKey HeaderKey) http.Handler

CheckHeader is a wrapper which adds a value from the request header to context if one does not yet exist.

func CheckHeaderMiddleware added in v1.0.3

func CheckHeaderMiddleware(headerKey HeaderKey) func(http.Handler) http.Handler

CheckHeaderMiddleware returns a CheckHeader function for the provided header key as a middleware function (alice middleware Constructor, ie. func(http.Handler) -> (http.Handler))

Types

type CookieKey

type CookieKey int

CookieKey - iota enum of possible cookie keys

const (
	UserAccessCookieKey CookieKey = iota
	LocaleCookieKey
	CollectionIDCookieKey
)

Possible values for cookie keys

func (CookieKey) ContextKey

func (ck CookieKey) ContextKey() interface{}

ContextKey returns the context key corresponding to a cookie key

func (CookieKey) String

func (ck CookieKey) String() string

String returns the string representation of a cookie key

type HeaderKey

type HeaderKey int

HeaderKey - iota enum of possible header keys

const (
	UserAccessHeaderKey HeaderKey = iota
	LocaleHeaderKey
	CollectionIDHeaderKey
)

Possible values for header keys

func (HeaderKey) ContextKey

func (hk HeaderKey) ContextKey() interface{}

ContextKey returns the context key corresponding to a header key

func (HeaderKey) String

func (hk HeaderKey) String() string

String returns the string representation of a header key

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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