Documentation
¶
Index ¶
- func MethodMatcher(route *Route, request *http.Request) bool
- type Matcher
- type MatcherFunc
- type Route
- func (r *Route) AddMatcher(matcher Matcher)
- func (r *Route) Matches(request *http.Request) bool
- func (r *Route) Methods() []string
- func (r *Route) Name() string
- func (r *Route) Path() string
- func (r *Route) SetHandler(handler http.Handler)
- func (r *Route) SetMethods(methods ...string)
- func (r *Route) SetName(name string)
- func (r *Route) SetPath(path string)
- type RouteCollection
- func (collection *RouteCollection) Add(route *Route)
- func (collection *RouteCollection) Count() int
- func (collection *RouteCollection) RefreshNamedRoutes()
- func (collection *RouteCollection) RouteByName(name string) *Route
- func (collection *RouteCollection) RoutesByPath(path string) *RouteMatchGroup
- type RouteMatchGroup
- type Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Matcher ¶
type Matcher interface {
// Match should run conditionals to check if the route and request match based on requirements.
Match(route *Route, request *http.Request) bool
}
Matcher is used to check if the given route matches a request based on the conditions set out in the Match function.
type MatcherFunc ¶
MatcherFunc is an adapter to allow the use of ordinary functions as a Matcher.
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route should contain all information needed to match a url path to a handler bound on the route.
func (*Route) AddMatcher ¶
AddMatcher will add a Matcher to the list. These are used to check if the route matches a specific request criteria.
func (*Route) Matches ¶
Matches will run all matchers to check if this route matches the passed in request.
func (*Route) Methods ¶
Methods will return a list of request methods that this route will respond to.
func (*Route) SetHandler ¶
SetHandler will set the handler that will be called if the route is matched.
func (*Route) SetMethods ¶
SetMethods will normalise and set the request methods for this route based on http.Method*.
type RouteCollection ¶
type RouteCollection struct {
// contains filtered or unexported fields
}
RouteCollection provides helpful ways of dealing with collections of Routes.
func NewRouteCollection ¶
func NewRouteCollection() *RouteCollection
NewRouteCollection creates an empty RouteCollection.
func (*RouteCollection) Add ¶
func (collection *RouteCollection) Add(route *Route)
Add a route to the collection. If the route has a name assigned it will be added to the list of named routes.
func (*RouteCollection) Count ¶
func (collection *RouteCollection) Count() int
Count will return the total number of routes in the collection.
func (*RouteCollection) RefreshNamedRoutes ¶
func (collection *RouteCollection) RefreshNamedRoutes()
RefreshNamedRoutes will clear the named routes list and add all named routes back from the all routes list. This is useful if a name is assigned to a route after it has been added to the collection.
func (*RouteCollection) RouteByName ¶
func (collection *RouteCollection) RouteByName(name string) *Route
RouteByName can be used to lookup a route by its name.
func (*RouteCollection) RoutesByPath ¶
func (collection *RouteCollection) RoutesByPath(path string) *RouteMatchGroup
RoutesByPath will lookup routes in the route trie and return a RoutMatchGroup containing any matched routes and the parsed params.
type RouteMatchGroup ¶
RouteMatchGroup is used to encapsulate found routes, when looked up by path, with the parsed named params from the url.
type Router ¶
type Router interface {
http.Handler
Dispatch(response http.ResponseWriter, request *http.Request)
SetNotFoundHandler(handler http.Handler)
Get(path string, handler http.Handler)
Post(path string, handler http.Handler)
Put(path string, handler http.Handler)
Patch(path string, handler http.Handler)
Delete(path string, handler http.Handler)
Any(path string, handler http.Handler)
Match(path string, handler http.Handler, methods ...string)
}
Router manages dispatching of requests to route handlers.
func NewRouter ¶
func NewRouter() Router
NewRouter will create a new router instance with an empty collection and a default NotFoundHandler.
func NewRouterFromCollection ¶
func NewRouterFromCollection(collection *RouteCollection) Router
NewRouterFromCollection will create a new router instance with a default NotFoundHandler and set the collection.