Documentation
¶
Index ¶
- Variables
- func Middleware(cfg *Config) wool.Middleware
- func ValuesFrom(data map[string][]string, name string) []string
- type Config
- type ErrorHandler
- type ExtractorSource
- type KeyAuth
- type Validator
- type ValueExtractorError
- type ValuesExtractor
- func CreateExtractors(lookups string) ([]ValuesExtractor, error)
- func ValuesFromCtx(name string) ValuesExtractor
- func ValuesFromForm(name string) ValuesExtractor
- func ValuesFromHeader(header string, valuePrefix string) ValuesExtractor
- func ValuesFromPath(param string) ValuesExtractor
- func ValuesFromQuery(param string) ValuesExtractor
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrHeaderExtractorValueMissing = &ValueExtractorError{message: "missing value in request header"} ErrHeaderExtractorValueInvalid = &ValueExtractorError{message: "invalid value in request header"} ErrQueryExtractorValueMissing = &ValueExtractorError{message: "missing value in query string"} ErrPathExtractorValueMissing = &ValueExtractorError{message: "missing value in path params"} ErrFormExtractorValueMissing = &ValueExtractorError{message: "missing value in form"} ErrCtxExtractorValueMissing = &ValueExtractorError{message: "missing value in ctx"} )
Functions ¶
func Middleware ¶
func Middleware(cfg *Config) wool.Middleware
Types ¶
type Config ¶
type Config struct {
// KeyLookup is a string in the form of "<source>:<name>" or "<source>:<name>,<source>:<name>" that is used
// to extract key from the request.
// Optional. Default value "header:Authorization".
// Possible values:
// - "header:<name>" or "header:<name>:<cut-prefix>"
// `<cut-prefix>` is argument value to cut/trim prefix of the extracted value. This is useful if header
// value has static prefix like `Authorization: <auth-scheme> <authorisation-parameters>` where part that we
// want to cut is `<auth-scheme> ` note the space at the end.
// In case of basic authentication `Authorization: Basic <credentials>` prefix we want to remove is `Basic `.
// - "query:<name>"
// - "form:<name>"
// - "cookie:<name>"
// Multiple sources example:
// - "header:Authorization,header:X-Api-Key"
KeyLookup string `mapstructure:"key_lookup"`
// ContinueOnIgnoredError allows the next middleware/handler to be called when ErrorHandler decides to
// ignore the error (by returning `nil`).
// This is useful when parts of your site/api allow public access and some authorized routes provide extra functionality.
// In that case you can use ErrorHandler to set a default public key auth value in the request context
// and continue. Some logic down the remaining execution chain needs to check that (public) key auth value then.
ContinueOnIgnoredError bool `mapstructure:"continue_on_ignored_error"`
// Validator is a function to validate key.
// Required.
Validator Validator
// ErrorHandler defines a function which is executed for an invalid key.
// It may be used to define a custom error.
ErrorHandler ErrorHandler
}
type ErrorHandler ¶
ErrorHandler defines a function which is executed for an invalid key.
type ExtractorSource ¶
type ExtractorSource string
const ( ExtractorSourceHeader ExtractorSource = "header" ExtractorSourceQuery ExtractorSource = "query" ExtractorSourcePath ExtractorSource = "path" ExtractorSourceForm ExtractorSource = "form" ExtractorSourceCtx ExtractorSource = "ctx" )
type ValueExtractorError ¶
type ValueExtractorError struct {
// contains filtered or unexported fields
}
func (*ValueExtractorError) Error ¶
func (e *ValueExtractorError) Error() string
type ValuesExtractor ¶
type ValuesExtractor func(c wool.Ctx) ([]string, ExtractorSource, error)
func CreateExtractors ¶
func CreateExtractors(lookups string) ([]ValuesExtractor, error)
func ValuesFromCtx ¶
func ValuesFromCtx(name string) ValuesExtractor
func ValuesFromForm ¶
func ValuesFromForm(name string) ValuesExtractor
func ValuesFromHeader ¶
func ValuesFromHeader(header string, valuePrefix string) ValuesExtractor
func ValuesFromPath ¶
func ValuesFromPath(param string) ValuesExtractor
func ValuesFromQuery ¶
func ValuesFromQuery(param string) ValuesExtractor
Click to show internal directories.
Click to hide internal directories.