Documentation ¶
Index ¶
- Constants
- func RedirectWithNextURL(r *request.Request, nextURL string)
- func ToHTTPHandler(h Handler) http.Handler
- func WalkRoutes(route *Route, f func(*Route, int))
- type ErrorHandlerMiddleware
- type HandleFunc
- type Handler
- type Middleware
- type Registrar
- type Route
- func (r *Route) AddGroup(group Registrar)
- func (r *Route) Any(path string, handler HandleFunc, name ...string) Registrar
- func (r *Route) Call(req *http.Request, args ...any) (*http.Response, error)
- func (r *Route) Delete(path string, handler HandleFunc, name ...string) Registrar
- func (r *Route) DisableMiddleware()
- func (r *Route) Get(path string, handler HandleFunc, name ...string) Registrar
- func (r *Route) Group(path string, name string, middlewares ...Middleware) Registrar
- func (r *Route) Handle(method, path string, handler http.Handler) Registrar
- func (r *Route) HandleFunc(method, path string, handler HandleFunc, name ...string) Registrar
- func (r *Route) Head(path string, handler HandleFunc, name ...string) Registrar
- func (r *Route) Invoke(dest http.ResponseWriter, req *http.Request, args ...any)
- func (r *Route) Match(method, path string) (bool, *Route, request.URLParams)
- func (r *Route) Name() string
- func (r *Route) Options(path string, handler HandleFunc, name ...string) Registrar
- func (r *Route) Patch(path string, handler HandleFunc, name ...string) Registrar
- func (r *Route) Post(path string, handler HandleFunc, name ...string) Registrar
- func (r *Route) Put(path string, handler HandleFunc, name ...string) Registrar
- func (r *Route) URL(method, name string) routevars.URLFormatter
- func (r *Route) Use(middlewares ...Middleware)
- type Router
- func (r *Router) AddGroup(group Registrar)
- func (r *Router) Any(path string, handler HandleFunc, name ...string) Registrar
- func (r *Router) Delete(path string, handler HandleFunc, name ...string) Registrar
- func (r *Router) Get(path string, handler HandleFunc, name ...string) Registrar
- func (r *Router) Group(path string, name string, middlewares ...Middleware) Registrar
- func (r *Router) Handle(method, path string, handler http.Handler) Registrar
- func (r *Router) HandleFunc(method, path string, handler HandleFunc, name ...string) Registrar
- func (r *Router) Head(path string, handler HandleFunc, name ...string) Registrar
- func (r *Router) Match(method, path string) (bool, *Route, request.URLParams)
- func (r *Router) Options(path string, handler HandleFunc, name ...string) Registrar
- func (r *Router) Patch(path string, handler HandleFunc, name ...string) Registrar
- func (r *Router) Post(path string, handler HandleFunc, name ...string) Registrar
- func (r *Router) Put(path string, handler HandleFunc, name ...string) Registrar
- func (r *Router) ServeHTTP(w http.ResponseWriter, rq *http.Request)
- func (r *Router) String() string
- func (r *Router) URL(method, name string) routevars.URLFormatter
- func (r *Router) URLFormat(name string, args ...interface{}) string
- func (r *Router) Use(middlewares ...Middleware)
- type Vars
Constants ¶
const ( GET = "GET" POST = "POST" PUT = "PUT" DELETE = "DELETE" PATCH = "PATCH" OPTIONS = "OPTIONS" HEAD = "HEAD" // Special method for matching all methods ALL = "ALL" )
HTTP Methods
Variables ¶
This section is empty.
Functions ¶
func RedirectWithNextURL ¶
Redirect user to a URL, appending the current URL as a "next" query parameter
func ToHTTPHandler ¶
Make a new http.Handler from a Handler
func WalkRoutes ¶
Recurse over a routes children, keeping track of depth
Types ¶
type ErrorHandlerMiddleware ¶ added in v3.2.6
type ErrorHandlerMiddleware func(error, *request.Request) Middleware
type HandleFunc ¶
HandleFunc is the function that is called when a route is matched
func HTTPWrapper ¶
func HTTPWrapper(handler func(http.ResponseWriter, *http.Request)) HandleFunc
Wrapper function for http.Handler to make it compatible with HandleFunc
func (HandleFunc) ServeHTTP ¶
func (f HandleFunc) ServeHTTP(r *request.Request)
type Handler ¶
Handler is the interface that wraps the ServeHTTP method.
func FromHTTPHandler ¶
Make a new handler from a http.Handler
type Middleware ¶
Middleware is the function that is called when a route is matched
type Registrar ¶
type Registrar interface { // Put registers a new route with the given path and method. Put(path string, handler HandleFunc, name ...string) Registrar // Post registers a new route with the given path and method. Post(path string, handler HandleFunc, name ...string) Registrar // Get registers a new route with the given path and method. Get(path string, handler HandleFunc, name ...string) Registrar // Delete registers a new route with the given path and method. Delete(path string, handler HandleFunc, name ...string) Registrar // Patch registers a new route with the given path and method. Patch(path string, handler HandleFunc, name ...string) Registrar // Options registers a new route with the given path and method. Options(path string, handler HandleFunc, name ...string) Registrar // Head registers a new route with the given path and method. Head(path string, handler HandleFunc, name ...string) Registrar // Register a route for all methods Any(path string, handler HandleFunc, name ...string) Registrar // HandleFunc registers a new route with the given path and method. HandleFunc(method, path string, handler HandleFunc, name ...string) Registrar // Handle is a convenience method that wraps the http.Handler in a HandleFunc Handle(method, path string, handler http.Handler) Registrar // Use adds middleware to the router. Use(middlewares ...Middleware) // Group creates a new router URL group Group(path string, name string, middlewares ...Middleware) Registrar // Addgroup adds a group of routes to the router AddGroup(group Registrar) // URL returns the URL for a named route URL(method, name string) routevars.URLFormatter // Call the route, returning the response and a possible error. Call(request *http.Request, args ...any) (*http.Response, error) // Invoke the route's handler, writing to a response writer. Invoke(dest http.ResponseWriter, req *http.Request, args ...any) }
Registrar is the main interface for registering routes
type Route ¶
type Route struct { Method string Path routevars.URLFormatter HandlerFunc HandleFunc // contains filtered or unexported fields }
Route is a single route in the router
func (*Route) Any ¶
func (r *Route) Any(path string, handler HandleFunc, name ...string) Registrar
Register a route for all methods
func (*Route) Call ¶ added in v3.1.7
Call a route handler with the given request.
Do so by making a HTTP request to the route's url.
If te url takes arguments, you need to pass them into Call.
It will run the route's middleware and the route's handler.
This will
func (*Route) Delete ¶
func (r *Route) Delete(path string, handler HandleFunc, name ...string) Registrar
Delete registers a new route with the given path and method.
func (*Route) DisableMiddleware ¶
func (r *Route) DisableMiddleware()
Disable the router's middlewares for this route, and all its children It will however still run the route's own middlewares.
func (*Route) Get ¶
func (r *Route) Get(path string, handler HandleFunc, name ...string) Registrar
Get registers a new route with the given path and method.
func (*Route) Group ¶
func (r *Route) Group(path string, name string, middlewares ...Middleware) Registrar
Group creates a new group of routes
func (*Route) HandleFunc ¶
func (r *Route) HandleFunc(method, path string, handler HandleFunc, name ...string) Registrar
HandleFunc registers a new route with the given path and method.
func (*Route) Head ¶
func (r *Route) Head(path string, handler HandleFunc, name ...string) Registrar
Head registers a new route with the given path and method.
func (*Route) Invoke ¶ added in v3.1.7
Invoke a route handler directly.
If te url takes arguments, you need to pass them into Invoke.
It will not run the route's middleware.
func (*Route) Name ¶
Return the name of the route This can be used to match a route with the URL method
func (*Route) Options ¶
func (r *Route) Options(path string, handler HandleFunc, name ...string) Registrar
Options registers a new route with the given path and method.
func (*Route) Patch ¶
func (r *Route) Patch(path string, handler HandleFunc, name ...string) Registrar
Patch registers a new route with the given path and method.
func (*Route) Post ¶
func (r *Route) Post(path string, handler HandleFunc, name ...string) Registrar
Post registers a new route with the given path and method.
func (*Route) Put ¶
func (r *Route) Put(path string, handler HandleFunc, name ...string) Registrar
Put registers a new route with the given path and method.
type Router ¶
type Router struct { NotFoundHandler Handler // contains filtered or unexported fields }
Router is the main router struct It takes care of dispatching requests to the correct route
func (*Router) Any ¶
func (r *Router) Any(path string, handler HandleFunc, name ...string) Registrar
Register a route for all methods
func (*Router) Delete ¶
func (r *Router) Delete(path string, handler HandleFunc, name ...string) Registrar
Delete registers a new route with the given path and method.
func (*Router) Get ¶
func (r *Router) Get(path string, handler HandleFunc, name ...string) Registrar
Get registers a new route with the given path and method.
func (*Router) Group ¶
func (r *Router) Group(path string, name string, middlewares ...Middleware) Registrar
Group creates a new router URL group
func (*Router) HandleFunc ¶
func (r *Router) HandleFunc(method, path string, handler HandleFunc, name ...string) Registrar
HandleFunc registers a new route with the given path and method.
func (*Router) Head ¶
func (r *Router) Head(path string, handler HandleFunc, name ...string) Registrar
Head registers a new route with the given path and method.
func (*Router) Options ¶
func (r *Router) Options(path string, handler HandleFunc, name ...string) Registrar
Options registers a new route with the given path and method.
func (*Router) Patch ¶
func (r *Router) Patch(path string, handler HandleFunc, name ...string) Registrar
Patch registers a new route with the given path and method.
func (*Router) Post ¶
func (r *Router) Post(path string, handler HandleFunc, name ...string) Registrar
Post registers a new route with the given path and method.
func (*Router) Put ¶
func (r *Router) Put(path string, handler HandleFunc, name ...string) Registrar
Put registers a new route with the given path and method.
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, rq *http.Request)
ServeHTTP dispatches the request to the handler whose pattern matches the request URL.
func (*Router) String ¶ added in v3.2.7
Returns all the routes in a nicely formatted string for debugging.
func (*Router) URL ¶
func (r *Router) URL(method, name string) routevars.URLFormatter
Get a route by name.
Route names are optional, when used a route's child can be access like so:
It looks like Django's URL routing syntax.
router.Route("routeName")
router.Route("parentName:routeToGet")
func (*Router) URLFormat ¶
The URL func, but for easy use in templates.
It returns the URL, formatted based on the arguments.
func (*Router) Use ¶
func (r *Router) Use(middlewares ...Middleware)
Use adds middleware to the router.