middleware

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: MIT Imports: 14 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

Overview

Package middleware provides multiple middlewares, useful for any HTTP service. These middlewares are not specific to any application, and are made to be as reusable and idiomatic as possible. Compatibility is guaranteed for `net/http`, however these middlewares should be compatible with any third-party package which conforms to the standard library's APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compose

func Compose(h http.Handler, m ...Middleware) http.Handler

Compose adds middleware handlers to a given handler. Middleware handlers are ordered from first to last.

func Etag

func Etag(next http.Handler) http.Handler

Etag middleware sets the ETag header.

func Recover

func Recover(next http.Handler) http.Handler

Recover middleware recovers from panics, and logs the error.

func SetHeader added in v0.23.0

func SetHeader(key, value string) func(next http.Handler) http.Handler

SetHeader adds header key/values to the response.

Types

type AppHeadersOptions added in v0.23.0

type AppHeadersOptions struct {
	GitCommit string
	Name      string
	Region    string
	Version   string
}

AppHeaders holds app specific header values.

type AuthOptions added in v0.23.0

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

AuthOptions holds the necessary values for the authentication middleware

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 NewEtagWriter added in v0.23.0

func NewEtagWriter(w http.ResponseWriter) *EtagWriter

NewEtagWriter returns an EtagWriter with a wrapped ResponseWriter.

func (*EtagWriter) ClientEtag added in v0.23.0

func (e *EtagWriter) ClientEtag(t string) *EtagWriter

ClientEtag sets the requested ETag.

func (*EtagWriter) Write added in v0.1.1

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

Write overrides the wrapped http.ResponseWriter's Write method, to provide etag-specific headers.

type LoggerOptions added in v0.23.0

type LoggerOptions struct {
	GitCommit string
	Name      string
	Version   string
}

LoggerOptions holds all logger middleware options.

type Middleware

type Middleware = func(http.Handler) http.Handler

Middleware aliases the function type for all middleware.

func AppHeaders

func AppHeaders(opts AppHeadersOptions) Middleware

AppHeaders adds more app-specific headers to the response.

func Auth

func Auth(opts AuthOptions) Middleware

Auth handles authenticating requests. Authentication is driven by an API key query parameter.

func Logger

func Logger(opts LoggerOptions) Middleware

Logger outputs general information about requests.

func Secure

func Secure(opts secure.Options) Middleware

Secure creates the security middleware

func SecureDefault added in v0.23.0

func SecureDefault() Middleware

SecureDefault is similar to Secure, but provides sane security defaults, without requiring options to be provided.

Jump to

Keyboard shortcuts

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