Documentation ¶
Overview ¶
Package router is a middleware that works well (but not exclusively) with rkusa/web(https://github.com/rkusa/web) and provides high performance HTTP request routing using httptreemux(http://github.com/dimfeld/httptreemux).
routes := router.New() routes.GET("/users/:id", func(rw http.ResponseWriter, r *http.Request) { id := router.Param(r, "id") // ... }) app.Use(routes.Middleware())
Index ¶
- func Param(r *http.Request, name string) string
- func ParamFromContext(ctx context.Context, name string) string
- type Router
- func (rt *Router) DELETE(path string, handler http.HandlerFunc)
- func (rt *Router) GET(path string, handler http.HandlerFunc)
- func (rt *Router) Group(path string) *Router
- func (rt *Router) HEAD(path string, handler http.HandlerFunc)
- func (rt *Router) Handle(method, path string, handler http.HandlerFunc)
- func (rt *Router) Middleware() func(http.ResponseWriter, *http.Request, http.HandlerFunc)
- func (rt *Router) OPTIONS(path string, handler http.HandlerFunc)
- func (rt *Router) PATCH(path string, handler http.HandlerFunc)
- func (rt *Router) POST(path string, handler http.HandlerFunc)
- func (rt *Router) PUT(path string, handler http.HandlerFunc)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router can be used to dispatch requests to different handler functions via configurable routes
func (*Router) DELETE ¶
func (rt *Router) DELETE(path string, handler http.HandlerFunc)
DELETE is a shortcut for router.Handle("DELETE", path, handle)
func (*Router) GET ¶
func (rt *Router) GET(path string, handler http.HandlerFunc)
GET is a shortcut for router.Handle("GET", path, handle)
func (*Router) Group ¶
Group creates a new route group with the given path prefix. All route created using the returned Router are prefixed accoringly.
func (*Router) HEAD ¶
func (rt *Router) HEAD(path string, handler http.HandlerFunc)
HEAD is a shortcut for router.Handle("HEAD", path, handle)
func (*Router) Handle ¶
func (rt *Router) Handle(method, path string, handler http.HandlerFunc)
Handle registers a new request handle with the given path and method.
func (*Router) Middleware ¶
func (rt *Router) Middleware() func(http.ResponseWriter, *http.Request, http.HandlerFunc)
Middleware returns a middleware that serves all registered routes.
func (*Router) OPTIONS ¶
func (rt *Router) OPTIONS(path string, handler http.HandlerFunc)
OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle)
func (*Router) PATCH ¶
func (rt *Router) PATCH(path string, handler http.HandlerFunc)
PATCH is a shortcut for router.Handle("PATCH", path, handle)