func FileServe(dir string) http.HandlerFunc
FileServe returns a new http.HandlerFunc that serves files from dir. Using routes must provide the *filepath parameter.
func Param(ctx context.Context, p string) string
Param returns param p for the context, or the empty string when param does not exist in context.
func WithParam(ctx context.Context, p, v string) context.Context
WithParam returns a new context with param p set to v.
Router wraps httprouter.Router and adds support for prefixed sub-routers, per-request context injections and instrumentation.
type Router struct {
// contains filtered or unexported fields
}
func New() *Router
New returns a new Router.
func (r *Router) Del(path string, h http.HandlerFunc)
Del registers a new DELETE route.
func (r *Router) Get(path string, h http.HandlerFunc)
Get registers a new GET route.
func (r *Router) Head(path string, h http.HandlerFunc)
Head registers a new HEAD route.
func (r *Router) Options(path string, h http.HandlerFunc)
Options registers a new OPTIONS route.
func (r *Router) Post(path string, h http.HandlerFunc)
Post registers a new POST route.
func (r *Router) Put(path string, h http.HandlerFunc)
Put registers a new PUT route.
func (r *Router) Redirect(w http.ResponseWriter, req *http.Request, path string, code int)
Redirect takes an absolute path and sends an internal HTTP redirect for it, prefixed by the router's path prefix. Note that this method does not include functionality for handling relative paths or full URL redirects.
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements http.Handler.
func (r *Router) WithInstrumentation(instrh func(handlerName string, handler http.HandlerFunc) http.HandlerFunc) *Router
WithInstrumentation returns a router with instrumentation support.
func (r *Router) WithPrefix(prefix string) *Router
WithPrefix returns a router that prefixes all registered routes with prefix.