Documentation ¶
Index ¶
- Constants
- func HTTPHandler(c alice.Chain, fs http.Handler) http.Handler
- func LogHandler() func(http.Handler) http.Handler
- func Param(ctx context.Context, key string) string
- type AddHandlerEvent
- type Event
- type MethodNotAllowedHandlerEvent
- type NotFoundHandlerEvent
- type Route
- type Router
- type RouterGroup
Constants ¶
const ParamsKey = "params"
ParamsKey is the key for contexts which grant access to the url params.
Variables ¶
This section is empty.
Functions ¶
func HTTPHandler ¶
HTTPHandler wraps a raw http.Handler in chain middleware.
func LogHandler ¶
LogHandler instantiates a new xlog HTTP handler using the given log.
Types ¶
type AddHandlerEvent ¶
AddHandlerEvent is fired whenever a generic handler is added to the router.
type Event ¶
type Event interface{}
Event represents router events which will fire as the router is being configured. This is used more as a debug tool than anything.
type MethodNotAllowedHandlerEvent ¶
type MethodNotAllowedHandlerEvent struct { }
MethodNotAllowedHandlerEvent is fired when a MethodNotAllowed handler is set for the router.
type NotFoundHandlerEvent ¶
type NotFoundHandlerEvent struct { }
NotFoundHandlerEvent is fired when a NotFound handler is set for the router.
type Route ¶
Route is a function with exposes the request context as an argument. For Go 1.7+, the request has an attached context. This provides for backward compatibility for the many handlers written before the Go 1.7.
type Router ¶
type Router interface { RouterGroup // Static adds a directory of static content to serve at root. StaticRoot(fs http.Handler) // StaticFiles adds a directory of static content to a specific path. StaticFiles(path string, fs http.Handler) // NotFound adds a handler for routes that don't exist. NotFound(http.Handler) // MethodNotAllowed handles requests in which the route exists but hte wrong method was used. MethodNotAllowed(http.Handler) // Handler returns an http.Handler Handler() http.Handler // EventHandler calls the given function for each handler as it is added to the router. EventHandler(func(evt Event)) }
Router defines a root router for handling requests.
type RouterGroup ¶
type RouterGroup interface { // Use adds middleware to the router. Use(f func(next http.Handler) http.Handler) // Chain returns the middleware chain. Chain() alice.Chain // Group returns a new router which strips the given path before the request is handled. All middleware is transferred to the child group. Group(path string) RouterGroup // Path returns the root path of the RouterGroup Path() string // GET adds a GET handler at the given path. GET(path string, handler Route) // POST adds a POST handler at the given path. POST(path string, handler Route) // PUT adds a PUT handler at the given path. PUT(path string, handler Route) // OPTIONS adds a OPTIONS handler at the given path. OPTIONS(path string, handler Route) // HEAD adds a HEAD handler at the given path. HEAD(path string, handler Route) // PATCH adds a PATCH handler at the given path. PATCH(path string, handler Route) // DELETE adds a DELETE handler at the given path. DELETE(path string, handler Route) }
RouterGroup allows for grouping routes with separate middleware.