mw: github.com/morhekil/mw Index | Examples | Files | Directories

package mw

import "github.com/morhekil/mw"

Package mw is a collection of various Go middlewares. For details about any non-trivial middlewares, refer to the documentation of the corresponding sub-package.

Feel free to open issues and/or features requests on project's GitHub page at https://github.com/morhekil/mw

Code:

// Sample application that combines all included
// middlewares together into a single stack
app := http.NotFoundHandler()

hs := map[string]string{
    "Content-Type": "application/json; charset=utf-8",
}

a := alice.New(
    mw.Recover,
    mw.Logger,
    mw.Chaotic("/chaotic"),
    mw.Gzip,
    mw.Headers(hs),
).Then(app)

http.ListenAndServe(":1234", a)

Index

Examples

Package Files

chaotic.go gzip.go headers.go logger.go mw.go recover.go util.go

func Chaotic Uses

func Chaotic(url string) func(h http.Handler) http.Handler

Chaotic middleware allows to inject configurable delays and failures into the requests processed by its underlying HTTP stack. It provides a configuration page, mounted under the specified URL.

Example:

http.ListenAndServe(":1234",
	// wrap application handler with chaotic.H,
	// installing its pages under /chaotic URL
	mw.Chaotic("/chaotic")(app),
)

Read chaotic package documentation for more details: on github (https://github.com/morhekil/mw/tree/master/chaotic), or on godoc (http://godoc.org/github.com/morhekil/mw/chaotic).

func Gzip Uses

func Gzip(h http.Handler) http.Handler

Gzip middleware turns response writer w into a gzip response writer if the appropriate Accept-Encoding headers are present

func Headers Uses

func Headers(hs map[string]string) func(h http.Handler) http.Handler

Headers to be written into all responses from the application. Example:

hs := map[string]string{
    "Content-Type":   "application/json; charset=utf-8",
}
http.ListenAndServe(":1234", mw.Headers(hs)(app))

func Logger Uses

func Logger(h http.Handler) http.Handler

Logger middleware writes all incoming requests into stdout using the format:

<time>\t<ip>\t"<method> <URI>"\t<runtime>

E.g.

2015/02/01 19:19:31 127.0.0.1     "GET /Ping"     31.376µs

IP address prefers X-Real-IP or X-Forwarded-For headers, if present, or falls back to http.Request's RemoteAddr otherwise.

func Recover Uses

func Recover(h http.Handler) http.Handler

Recover from panic when it happened in the application. Details of the panic are written into Stderr, together with some information about the request- client's real IP address, HTTP method and URL path.

Directories

PathSynopsis
chaoticPackage chaotic provides stdlib-compatible middleware to inject configurable delays and failures into the requests processed by its underlying HTTP stack.
chaotic/bindata

Package mw imports 8 packages (graph) and is imported by 2 packages. Updated 2016-07-23. Refresh now. Tools for package owners.