Awesome
claw
What is claw ?
Claw is a Middleware chaining module, compatible with
every mux who respects the http.Handler
interface. Claw allows you
to create Stack of middleware for specific tasks.
Features
func (http.ResponseWriter, *http.Request)
andfunc(http.Handler) http.Handler
as Middleware.- Global Middleware.
- Create Middleware Stack.
- Claw runs middleware in order: last enter first to run
[ squiidz/claw/mw
content a simple logger and gzip compressor middleware ]
Example
package main
import "github.com/go-zoo/claw"
func main() {
// Create a new Claw instance, and set some Global Middleware.
c := claw.New(GlobalMiddleWare)
// You can also, create a Stack(), which is a stack
// of MiddleWare for a specific task
auth := c.NewStack(CheckUser, CheckToken, ValidSession)
// Wrap your global middleware with your handler
http.Handle("/home", c.Use(YourHandler))
// Add some middleware on a specific handler.
http.Handle("/", c.Use(YourOtherHandler).Add(OtherMiddle))
// Add a Stack to the route.
http.Handle("/", c.Use(YourOtherHandler).Stack(auth))
// Start Listening
// You can also wrap the global middlewares directly on the router
// instead of declaring claw.Use() on every handler,
// use http.ListenAndServe(":8080", claw.Merge(mux))
http.ListenAndServe(":8080", nil)
}
TODO
- DOC
- Refactoring
- Debugging
Contributing
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Write Tests!
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
License
MIT
Links
Lightning Fast HTTP Mux : Bone