claw

package module
v0.0.0-...-4469563 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2015 License: MIT Imports: 4 Imported by: 5 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

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

Lightning Fast HTTP Mux : Bone

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Claw

type Claw struct {
	Handlers []MiddleWare
}

Claw is the array of the Global Middleware

func New

func New(m ...interface{}) *Claw

New create a new empty Claw

func (*Claw) Merge

func (c *Claw) Merge(h http.Handler) *ClawHandler

Merge all the global middleware with the provided http.HandlerFunc

func (*Claw) Use

func (c *Claw) Use(h http.HandlerFunc) *ClawHandler

Use, merge all the global middleware with the provided http.HandlerFunc

type ClawFunc

type ClawFunc func(rw http.ResponseWriter, req *http.Request)

ClawFunc redefine http.HandlerFunc

func (ClawFunc) ServeHTTP

func (c ClawFunc) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Serve HTTP Request

type ClawHandler

type ClawHandler struct {
	http.Handler
}

CalwHandler only wrap a http.Handler

func (*ClawHandler) Add

func (c *ClawHandler) Add(m ...interface{}) *ClawHandler

Add some middleware to a particular handler

func (*ClawHandler) Stack

func (c *ClawHandler) Stack(stk ...Stack) *ClawHandler

Stack takes a Stack type variable and use it on the ClawHandler who call the function.

type MiddleWare

type MiddleWare func(http.Handler) http.Handler

Middleware is the signature of a valid middleware with Claw

type Stack

type Stack []MiddleWare

Stack is use to create some predefine middleware stack.

func NewStack

func NewStack(m ...interface{}) Stack

NewStack generate a New Stack with the provided Middleware.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址