Documentation ¶
Index ¶
- Variables
- type PropSetter
- type Route
- func (r *Route) ApplyProps(props ...PropSetter)
- func (r *Route) Audit(audit bool) *Route
- func (r *Route) GetConfig() *RouteConfig
- func (r *Route) GetError() error
- func (r *Route) GetHandler() http.Handler
- func (r *Route) GetName() string
- func (r *Route) GetProps(key string) interface{}
- func (r *Route) Handler(handler http.Handler) *Route
- func (r *Route) HandlerFunc(f func(http.ResponseWriter, *http.Request)) *Route
- func (r *Route) Headers(pairs ...string) *Route
- func (r *Route) HeadersRegexp(pairs ...string) *Route
- func (r *Route) Host(tpl string) *Route
- func (r *Route) Methods(methods ...string) *Route
- func (r *Route) Name(name string) *Route
- func (r *Route) Path(tpl string) *Route
- func (r *Route) PathPrefix(tpl string) *Route
- func (r *Route) Queries(pairs ...string) *Route
- func (r *Route) Restricted(restricted bool) *Route
- func (r *Route) Schemes(schemes ...string) *Route
- func (r *Route) SetConfig(config RouteConfig) *Route
- func (r *Route) SetProps(key string, prop interface{}) *Routedeprecated
- func (r *Route) SkipClean() bool
- func (r *Route) Subrouter() *Router
- type RouteConfig
- type RouteProps
- type RouteRegister
- type Router
- func (r *Router) Audit(audit bool)
- func (r *Router) Get(name string) *Route
- func (r *Router) GetRoute(name string) *Route
- func (r *Router) GetRouteConfig(route *mux.Route) *RouteConfig
- func (r *Router) Handle(path string, handler http.Handler) *Route
- func (r *Router) HandleFunc(path string, f func(http.ResponseWriter, *http.Request)) *Route
- func (r *Router) Headers(pairs ...string) *Route
- func (r *Router) Host(tpl string) *Route
- func (r *Router) Methods(methods ...string) *Route
- func (r *Router) Name(name string) *Route
- func (r *Router) NewRoute() *Route
- func (r *Router) Path(tpl string) *Route
- func (r *Router) PathPrefix(tpl string) *Route
- func (r *Router) Queries(pairs ...string) *Route
- func (r *Router) Register(regs ...RouteRegister)
- func (r *Router) Restricted(restricted bool)
- func (r *Router) Schemes(schemes ...string) *Route
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) SkipClean(value bool) *Router
- func (r *Router) StrictSlash(value bool) *Router
- func (r *Router) Use(mwf ...func(http.Handler) http.Handler)
- func (r *Router) UseEncodedPath() *Router
Constants ¶
This section is empty.
Variables ¶
var ErrPropConflict = errors.New("same key exists in route props")
var ErrPropIsNil = errors.New("props is not initialized")
Functions ¶
This section is empty.
Types ¶
type PropSetter ¶
type PropSetter func(props *RouteProps)
func Props ¶
func Props(key string, val interface{}) PropSetter
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
func (*Route) ApplyProps ¶
func (r *Route) ApplyProps(props ...PropSetter)
func (*Route) GetConfig ¶
func (r *Route) GetConfig() *RouteConfig
func (*Route) GetHandler ¶
GetHandler returns the handler for the route, if any.
func (*Route) HandlerFunc ¶
HandlerFunc sets a handler function for the route.
func (*Route) HeadersRegexp ¶
HeadersRegexp accepts a sequence of key/value pairs, where the value has regex support. For example:
r := mux.NewRouter() r.HeadersRegexp("Content-Type", "application/(text|json)", "X-Requested-With", "XMLHttpRequest")
The above route will only match if both the request header matches both regular expressions. If the value is an empty string, it will match any value if the key is set. Use the start and end of string anchors (^ and $) to match an exact value.
func (*Route) Host ¶
Host adds a matcher for the URL host. It accepts a template with zero or more URL variables enclosed by {}. Variables can define an optional regexp pattern to be matched:
- {name} matches anything until the next dot.
- {name:pattern} matches the given regexp pattern.
For example:
r := mux.NewRouter() r.Host("www.example.com") r.Host("{subdomain}.domain.com") r.Host("{subdomain:[a-z]+}.domain.com")
Variable names must be unique in a given route. They can be retrieved calling mux.Vars(request).
func (*Route) Methods ¶
Methods adds a matcher for HTTP methods. It accepts a sequence of one or more methods to be matched, e.g.: "GET", "POST", "PUT".
func (*Route) Name ¶
Name sets the name for the route, used to build URLs. It is an error to call Name more than once on a route.
func (*Route) Path ¶
Path adds a matcher for the URL path. It accepts a template with zero or more URL variables enclosed by {}. The template must start with a "/". Variables can define an optional regexp pattern to be matched:
- {name} matches anything until the next slash.
- {name:pattern} matches the given regexp pattern.
For example:
r := mux.NewRouter() r.Path("/products/").Handler(ProductsHandler) r.Path("/products/{key}").Handler(ProductsHandler) r.Path("/articles/{category}/{id:[0-9]+}"). Handler(ArticleHandler)
Variable names must be unique in a given route. They can be retrieved calling mux.Vars(request).
func (*Route) PathPrefix ¶
PathPrefix adds a matcher for the URL path prefix. This matches if the given template is a prefix of the full URL path. See Route.Path() for details on the tpl argument.
Note that it does not treat slashes specially ("/foobar/" will be matched by the prefix "/foo") so you may want to use a trailing slash here.
Also note that the setting of Router.StrictSlash() has no effect on routes with a PathPrefix matcher.
func (*Route) Queries ¶
Queries adds a matcher for URL query values. It accepts a sequence of key/value pairs. Values may define variables. For example:
r := mux.NewRouter() r.Queries("foo", "bar", "id", "{id:[0-9]+}")
The above route will only match if the URL contains the defined queries values, e.g.: ?foo=bar&id=42.
If the value is an empty string, it will match any value if the key is set.
Variables can define an optional regexp pattern to be matched:
- {name} matches anything until the next slash.
- {name:pattern} matches the given regexp pattern.
func (*Route) Restricted ¶
func (*Route) Schemes ¶
Schemes adds a matcher for URL schemes. It accepts a sequence of schemes to be matched, e.g.: "http", "https".
func (*Route) SetConfig ¶
func (r *Route) SetConfig(config RouteConfig) *Route
type RouteConfig ¶
type RouteConfig struct {
// contains filtered or unexported fields
}
func NewConfig ¶
func NewConfig() RouteConfig
func (RouteConfig) GetCopy ¶
func (rc RouteConfig) GetCopy(includeProp ...bool) RouteConfig
func (*RouteConfig) GetProps ¶
func (rc *RouteConfig) GetProps(key string) interface{}
func (RouteConfig) IsAuditEnable ¶
func (rc RouteConfig) IsAuditEnable() bool
func (RouteConfig) IsRestricted ¶
func (rc RouteConfig) IsRestricted() bool
func (*RouteConfig) SetProps ¶
func (rc *RouteConfig) SetProps(key string, prop interface{})
type RouteProps ¶
type RouteProps struct {
// contains filtered or unexported fields
}
func (*RouteProps) Get ¶
func (rp *RouteProps) Get(key string) (val interface{}, ok bool)
func (*RouteProps) Set ¶
func (rp *RouteProps) Set(key string, val interface{}) error
type RouteRegister ¶
type RouteRegister func(r *Router)
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) GetRouteConfig ¶
func (r *Router) GetRouteConfig(route *mux.Route) *RouteConfig
func (*Router) Handle ¶
Handle registers a new route with a matcher for the URL path. See Route.Path() and Route.Handler().
func (*Router) HandleFunc ¶
HandleFunc registers a new route with a matcher for the URL path. See Route.Path() and Route.HandlerFunc().
func (*Router) Headers ¶
Headers registers a new route with a matcher for request header values. See Route.Headers().
func (*Router) Methods ¶
Methods registers a new route with a matcher for HTTP methods. See Route.Methods().
func (*Router) PathPrefix ¶
PathPrefix registers a new route with a matcher for the URL path prefix. See Route.PathPrefix().
func (*Router) Queries ¶
Queries registers a new route with a matcher for URL query values. See Route.Queries().
func (*Router) Register ¶
func (r *Router) Register(regs ...RouteRegister)
func (*Router) Restricted ¶
func (*Router) Schemes ¶
Schemes registers a new route with a matcher for URL schemes. See Route.Schemes().