webutil

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2019 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderAPIKey = "X-modprox-api-key"
)

Variables

This section is empty.

Functions

func Chain

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

Chain recursively chains middleware together.

func ParseURL

func ParseURL(t *testing.T, tsURL string) (string, int)

ParseURL parses tsURL, triggering a failure on t if it is not possible to do so.

func WriteJSON

func WriteJSON(w http.ResponseWriter, i interface{})

Write the given struct as JSON into w.

Types

type Middleware

type Middleware func(http.Handler) http.Handler

A Middleware is used to execute intermediate Handlers in response to a request.

func KeyGuard

func KeyGuard(keys []string) Middleware

KeyGuard creates a Middleware which protects access to a handler by first checking for the X-modprox-api-key header being set. If at least one of the values for the header matches one of the keys configured for the KeyGuard, the handler is executed for the request. Otherwise, a StatusForbidden response is returned.

Jump to

Keyboard shortcuts

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