middleware

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2019 License: MIT Imports: 12 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compose

func Compose(handler http.Handler, middlewares ...Middleware) http.Handler

Compose adds middleware handlers to a given handler.

func Create

func Create(config Config) http.Handler

Create returns the default middleware composition, useful for all general services. Middleware should be added in a specific order. If any new middleware depends on other middleware, the new middleware should follow afterward.

func Etag

func Etag(handler http.Handler) http.Handler

Etag middleware sets the ETag header. Note, this middleware is only useful for buffered response bodies.

func Logger

func Logger(handler http.Handler) http.Handler

Logger outputs general information about requests.

func Recover

func Recover(handler http.Handler) http.Handler

Recover middleware recovers from panics, and logs the error.

Types

type AppHeaders

type AppHeaders struct {
	AppName     string
	AppVersion  string
	GitRevision string
	Region      string
}

AppHeaders holds app specific header values

type AuthConfig

type AuthConfig struct {
	WhiteList    []string
	APIKeyName   string
	SecretKey    string
	ErrorMessage string
}

AuthConfig holds the necessary values for the authentication middleware

type Config

type Config struct {
	Auth              bool
	AppName           string
	AppVersion        string
	Compress          bool
	EnvVarsToValidate []string
	GitRevision       string
	Handler           http.Handler
	Region            string
	SecureOptions     secure.Options
	WhiteList         []string
}

Config holds the values needed for Create()

type EtagWriter added in v0.1.1

type EtagWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

EtagWriter provides a ResponseWriter which holds info needed for verifying etags.

func (*EtagWriter) Write added in v0.1.1

func (e *EtagWriter) Write(p []byte) (int, error)

func (*EtagWriter) WriteHeader added in v0.1.1

func (e *EtagWriter) WriteHeader(status int)

WriteHeader must be defined to override the ResponseWriter's WriteHeader. This is needed to set the etag header in etagWriter.Write, as ResponseWriter's WriteHeader prevents setting headers after it is called.

type HealthConfig

type HealthConfig struct {
	Path     string
	Callback func() map[string]string
}

HealthConfig holds the information required by the Health middleware

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware represents the function type for all middleware.

func Auth

func Auth(config AuthConfig) Middleware

Auth handles authenticating the request

func Headers

func Headers(appHeaders AppHeaders) Middleware

Headers adds more app specific headers to the response

func Health

func Health(config HealthConfig) Middleware

Health provides a route to get an app's health information

func Secure

func Secure(options secure.Options) Middleware

Secure creates the security middleware

Jump to

Keyboard shortcuts

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