type BuildVarsFunc(func)
BuildVarsFunc is the function signature used by custom build variable
functions (which can modify route variables before a route's URL is built).
func (*Route).BuildVarsFunc(f BuildVarsFunc) *Route
func (*Router).BuildVarsFunc(f BuildVarsFunc) *Route
type MiddlewareFunc(func)
MiddlewareFunc is a function which receives an http.Handler and returns another http.Handler.
Typically, the returned handler is a closure which does something with the http.ResponseWriter and http.Request passed
to it, and then calls the handler passed as parameter to the MiddlewareFunc.
(T) Middleware(handler http.Handler) http.Handler
func CORSMethodMiddleware(r *Router) MiddlewareFunc
func (*Router).Use(mwf ...MiddlewareFunc)
type WalkFunc(func)
WalkFunc is the type of the function called for each route visited by Walk.
At every invocation, it is given the current route, and the current router,
and a list of ancestor routes that lead to the current route.
func (*Router).Walk(walkFn WalkFunc) error
Exported Values
func CORSMethodMiddleware(r *Router) MiddlewareFunc
CORSMethodMiddleware automatically sets the Access-Control-Allow-Methods response header
on requests for routes that have an OPTIONS method matcher to all the method matchers on
the route. Routes that do not explicitly handle OPTIONS requests will not be processed
by the middleware. See examples for usage.
func CurrentRoute(r *http.Request) *Route
CurrentRoute returns the matched route for the current request, if any.
This only works when called inside the handler of the matched route
because the matched route is stored in the request context which is cleared
after the handler returns.
var ErrMethodMismatcherror
ErrMethodMismatch is returned when the method in the request does not match
the method defined against the route.
var ErrNotFounderror
ErrNotFound is returned when no route match is found.
func NewRouter() *Router
NewRouter returns a new router instance.
func SetURLVars(r *http.Request, val map[string]string) *http.Request
SetURLVars sets the URL variables for the given request, to be accessed via
mux.Vars for testing route behaviour. Arguments are not modified, a shallow
copy is returned.
This API should only be used for testing purposes; it provides a way to
inject variables into the request context. Alternatively, URL variables
can be set by making a route that captures the required variables,
starting a server and sending the request to that server.
var SkipRoutererror
SkipRouter is used as a return value from WalkFuncs to indicate that the
router that walk is about to descend down to should be skipped.
func Vars(r *http.Request) map[string]string
Vars returns the route variables for the current request, if any.
The pages are generated with Goldsv0.1.6. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project and developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.