middleware

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2017 License: Apache-2.0 Imports: 1 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// HTTP Header
	REQUEST_ID_HEADER = "X-Request-Id"
	USER_ID_HEADER    = "X-FOULKON-USER-ID"

	// Middleware names
	AUTHENTICATOR_MIDDLEWARE  = "AUTHENTICATOR"
	XREQUESTID_MIDDLEWARE     = "XREQUESTID"
	REQUEST_LOGGER_MIDDLEWARE = "REQUEST-LOGGER"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware interface {
	// Action to apply to each request
	Action(next http.Handler) http.Handler

	// Additional info that middleware use
	GetInfo(r *http.Request, mc *MiddlewareContext)
}

Middleware interface with operations that all middlewares must implement

type MiddlewareContext

type MiddlewareContext struct {
	// Authenticator middleware
	UserId string
	Admin  bool

	// X-Request-Id middleware
	XRequestId string
}

MiddlewareContext struct contains all parameters used in the context of middlewares

type MiddlewareHandler

type MiddlewareHandler struct {
	Middlewares map[string]Middleware
}

MiddlewareHandler handles the HTTP request and applies its list of middlewares before calling the API

func (*MiddlewareHandler) GetMiddlewareContext

func (mwh *MiddlewareHandler) GetMiddlewareContext(r *http.Request) *MiddlewareContext

GetMiddlewareContext method retrieves all information about middleware context applied to request

func (*MiddlewareHandler) Handle

func (mwh *MiddlewareHandler) Handle(apiHandler http.Handler) http.Handler

Handle method execute middlewares in correct order before API handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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