kteru / mc

Small package provides a simple way to chain http handlers ⛓️

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mc - Middleware Chainer

Small package provides a simple way to chain http handlers.

GoDoc Build Status Coverage Status

Installation

$ go get -u github.com/aptpod/mc

Example

func main() {
	common := []func(http.Handler) http.Handler{
		middleware.Logger(),
		middleware.Recovery(),
	}

	authn := middleware.Authn()

	// `common` only
	http.Handle("/signin", mc.Chain(http.HandlerFunc(handler.SignIn),
		common,
	))

	// `common` and `authn`
	http.Handle("/user", mc.Chain(http.HandlerFunc(handler.User),
		common, authn,
	))

	http.ListenAndServe("127.0.0.1:8080", nil)
}

About

Small package provides a simple way to chain http handlers ⛓️

License:MIT License


Languages

Language:Go 100.0%