Skip to content

alex-golang/claw

 
 

Repository files navigation

claw GoDoc Build Status

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.

alt tag

Features

  • func (http.ResponseWriter, *http.Request) and func(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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Write Tests!
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

License

MIT

Links

Lightning Fast HTTP Mux : Bone

About

Scratching Middleware Chaining

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%