Documentation ¶
Index ¶
- type Middleware
- type Router
- func (router *Router) AddMiddleware(middlewares ...Middleware)
- func (router *Router) BuildHandler() http.Handler
- func (router *Router) Delete(path string, handler http.Handler, middlewares ...Middleware)
- func (router *Router) Get(path string, handler http.Handler, middlewares ...Middleware)
- func (router *Router) Handle(method string, path string, handler http.Handler, middlewares ...Middleware)
- func (router *Router) ListenAndServe(addr string) error
- func (router *Router) Match(req *http.Request) bool
- func (router *Router) Patch(path string, handler http.Handler, middlewares ...Middleware)
- func (router *Router) Post(path string, handler http.Handler, middlewares ...Middleware)
- func (router *Router) Put(path string, handler http.Handler, middlewares ...Middleware)
- func (router *Router) Shutdown(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Middleware ¶
type Middleware func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
Middleware replicates the negroni.HandlerFunc type but decouples the code from the library
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is a wrapper around the gorilla mux router and the negroni middleware library. It has some convenience functions to make it easier to do per-route middleware
func (*Router) AddMiddleware ¶
func (router *Router) AddMiddleware(middlewares ...Middleware)
AddMiddleware adds middleware that will be applied to every request. Middleware handlers are executed in the order defined.
func (*Router) BuildHandler ¶
BuildHandler returns an http.Handler that can be used as the argument to http.ListenAndServe.
func (*Router) Delete ¶
func (router *Router) Delete(path string, handler http.Handler, middlewares ...Middleware)
Delete is a helper function to add a DELETE route
func (*Router) Get ¶
func (router *Router) Get(path string, handler http.Handler, middlewares ...Middleware)
Get is a helper function to add a GET route
func (*Router) Handle ¶
func (router *Router) Handle(method string, path string, handler http.Handler, middlewares ...Middleware)
Handle registers a route with the router. Internally, gorilla mux is used. See https://github.com/gorilla/mux for options available for the path, including variables. End a path with an asterisk "*" to create a wildcard route.
func (*Router) ListenAndServe ¶
ListenAndServe builds the final handler and passes it to http.ListenAndServe
func (*Router) Patch ¶
func (router *Router) Patch(path string, handler http.Handler, middlewares ...Middleware)
Patch is a helper function to add a PATCH route
func (*Router) Post ¶
func (router *Router) Post(path string, handler http.Handler, middlewares ...Middleware)
Post is a helper function to add a POST route