https://github.com/aptpod/mc
Small package provides a simple way to chain http handlers ⛓️
https://github.com/aptpod/mc
golang http
Last synced: about 1 year ago
JSON representation
Small package provides a simple way to chain http handlers ⛓️
- Host: GitHub
- URL: https://github.com/aptpod/mc
- Owner: aptpod
- License: mit
- Created: 2018-12-19T03:17:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-19T03:26:00.000Z (over 7 years ago)
- Last Synced: 2025-01-12T08:41:54.278Z (about 1 year ago)
- Topics: golang, http
- Language: Go
- Homepage:
- Size: 1.95 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
mc - Middleware Chainer
=======================
Small package provides a simple way to chain http handlers.
[](https://godoc.org/github.com/aptpod/mc)
[](https://travis-ci.org/aptpod/mc)
[](https://coveralls.io/github/aptpod/mc?branch=master)
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)
}
```