middleware

package
v0.0.0-...-4c29561 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2020 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UserKey = "_user_id_"

	ErrUnknownUser           = errors.New("unknown user")
	ErrEmptyList             = errors.New("empty user list provided")
	ErrNoUserProvided        = errors.New("no user provided in request context")
	ErrAuthHeaderWrongLength = errors.New("wrong length of authorization value")
	ErrMissingAuthHeader     = errors.New("missing authorization header")
)

Functions

func AllowedMethods

func AllowedMethods(allowedMethods []string) func(f http.HandlerFunc) http.HandlerFunc

func BasicAuthenticate

func BasicAuthenticate(logger *log.Logger, authFn AuthFn, realm string) func(http.HandlerFunc) http.HandlerFunc

BasicAuthenticate setups authenticate headers in request, and handles authenticate based on authFn. In case of valid user authentication, it also set user id (that was returned from authFn) in request's context, and can be retrieved by GetUser function.

func GetUser

func GetUser(r *http.Request) (string, error)

GetUser returns user from request's context, and error when user is not provided.

func Noop

func PanicInterceptor

func PanicInterceptor(f http.HandlerFunc) http.HandlerFunc

func PanicInterceptorWithLogger

func PanicInterceptorWithLogger(logger *log.Logger) func(f http.HandlerFunc) http.HandlerFunc

func SetHeaders

func SetHeaders(headers map[string]string) func(f http.HandlerFunc) http.HandlerFunc

func TimeTrack

func TimeTrack(logger *log.Logger) func(f http.HandlerFunc) http.HandlerFunc

Types

type AuthFn

type AuthFn func(string, string) (string, error)

func Authenticate

func Authenticate(expectedUser, expectedPassword string) AuthFn

Authenticate verify credentials against provided user and password.

func AuthenticateMap

func AuthenticateMap(userList map[string]string) AuthFn

Authenticate verify credentials against provided map (user => password).

Jump to

Keyboard shortcuts

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