lookup

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingValue = errors.New("no value present in request")

ErrMissingValue can be thrown by follow if value with a HTTP header, the value header needs to be set if value with URL Query, the query value variable is empty if value with a cookie, the value cookie is empty

Functions

func FromCookie

func FromCookie(r *http.Request, key string) (string, error)

FromCookie get value from Cookie key is a cookie key

func FromHeader

func FromHeader(r *http.Request, key, prefix string) (string, error)

FromHeader get value from header key is a header key, like "Authorization" prefix is a string in the header, like "Bearer", if it is empty, only will return value.

func FromQuery

func FromQuery(r *http.Request, key string) (string, error)

FromQuery get value from query key is a query key

Types

type ArgumentExtractor

type ArgumentExtractor string

ArgumentExtractor extracts a value from request arguments. This includes a POSTed form or GET URL arguments. This extractor calls `ParseMultipartForm` on the request

func (ArgumentExtractor) ExtractToken

func (e ArgumentExtractor) ExtractToken(r *http.Request) (string, error)

type CookieExtractor

type CookieExtractor string

CookieExtractor extracts a value from cookie.

func (CookieExtractor) ExtractToken

func (e CookieExtractor) ExtractToken(r *http.Request) (string, error)

type Extractor

type Extractor interface {
	ExtractToken(*http.Request) (string, error)
}

Extractor is an interface for extracting a value from an HTTP request. The ExtractToken method should return a value string or an error. If no value is present, you must return ErrMissingValue.

type HeaderExtractor

type HeaderExtractor struct {
	// The key of the header
	// Required
	Key string
	// Strips 'Bearer ' prefix from bearer value string.
	// Possible value is "Bearer"
	// Optional
	Prefix string
}

HeaderExtractor is an extractor for finding a value in a header. Looks at each specified header in order until there's a match

func (HeaderExtractor) ExtractToken

func (e HeaderExtractor) ExtractToken(r *http.Request) (string, error)

type Lookup

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

Lookup is a tool that looks up the value from http request, such as token

func NewLookup

func NewLookup(lookup string) *Lookup

NewLookup new a lookup. lookup is a string in the form of "<source>:<name>[:<prefix>]" that is used to extract value from the request. use like "header:<name>[:<prefix>],query:<name>,cookie:<name>,param:<name>" Optional, Default value "header:Authorization:Bearer" for json web token. Possible values: - "header:<name>:<prefix>", <prefix> is a special string in the header, Possible value is "Bearer" - "query:<name>" - "cookie:<name>"

func (*Lookup) ExtractToken

func (sf *Lookup) ExtractToken(r *http.Request) (string, error)

ExtractToken extract value from http request.

type MultiExtractor

type MultiExtractor []Extractor

MultiExtractor tries Extractors in order until one returns a value string or an error occurs

func (MultiExtractor) ExtractToken

func (e MultiExtractor) ExtractToken(req *http.Request) (string, error)

Jump to

Keyboard shortcuts

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