routex

package
v0.0.0-...-11273d6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2021 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPropConflict = errors.New("same key exists in route props")
View Source
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) Audit

func (r *Route) Audit(audit bool) *Route

func (*Route) GetConfig

func (r *Route) GetConfig() *RouteConfig

func (*Route) GetError

func (r *Route) GetError() error

GetError returns an error resulted from building the route, if any.

func (*Route) GetHandler

func (r *Route) GetHandler() http.Handler

GetHandler returns the handler for the route, if any.

func (*Route) GetName

func (r *Route) GetName() string

GetName returns the name for the route, if any.

func (*Route) GetProps

func (r *Route) GetProps(key string) interface{}

func (*Route) Handler

func (r *Route) Handler(handler http.Handler) *Route

Handler sets a handler for the route.

func (*Route) HandlerFunc

func (r *Route) HandlerFunc(f func(http.ResponseWriter, *http.Request)) *Route

HandlerFunc sets a handler function for the route.

func (*Route) Headers

func (r *Route) Headers(pairs ...string) *Route

func (*Route) HeadersRegexp

func (r *Route) HeadersRegexp(pairs ...string) *Route

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

func (r *Route) Host(tpl string) *Route

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

func (r *Route) Methods(methods ...string) *Route

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

func (r *Route) Name(name string) *Route

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

func (r *Route) Path(tpl string) *Route

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

func (r *Route) PathPrefix(tpl string) *Route

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

func (r *Route) Queries(pairs ...string) *Route

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 (r *Route) Restricted(restricted bool) *Route

func (*Route) Schemes

func (r *Route) Schemes(schemes ...string) *Route

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

func (*Route) SetProps deprecated

func (r *Route) SetProps(key string, prop interface{}) *Route

Deprecated: use ApplyProps and routex.Props(key, val) instead

func (*Route) SkipClean

func (r *Route) SkipClean() bool

SkipClean reports whether path cleaning is enabled for this route via Router.SkipClean.

func (*Route) Subrouter

func (r *Route) Subrouter() *Router

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 New

func New() *Router

func (*Router) Audit

func (r *Router) Audit(audit bool)

func (*Router) Get

func (r *Router) Get(name string) *Route

func (*Router) GetRoute

func (r *Router) GetRoute(name string) *Route

func (*Router) GetRouteConfig

func (r *Router) GetRouteConfig(route *mux.Route) *RouteConfig

func (*Router) Handle

func (r *Router) Handle(path string, handler http.Handler) *Route

Handle registers a new route with a matcher for the URL path. See Route.Path() and Route.Handler().

func (*Router) HandleFunc

func (r *Router) HandleFunc(path string, f func(http.ResponseWriter, *http.Request)) *Route

HandleFunc registers a new route with a matcher for the URL path. See Route.Path() and Route.HandlerFunc().

func (*Router) Headers

func (r *Router) Headers(pairs ...string) *Route

Headers registers a new route with a matcher for request header values. See Route.Headers().

func (*Router) Host

func (r *Router) Host(tpl string) *Route

Host registers a new route with a matcher for the URL host. See Route.Host().

func (*Router) Methods

func (r *Router) Methods(methods ...string) *Route

Methods registers a new route with a matcher for HTTP methods. See Route.Methods().

func (*Router) Name

func (r *Router) Name(name string) *Route

Name registers a new route with a name. See Route.Name().

func (*Router) NewRoute

func (r *Router) NewRoute() *Route

NewRoute registers an empty route.

func (*Router) Path

func (r *Router) Path(tpl string) *Route

Path registers a new route with a matcher for the URL path. See Route.Path().

func (*Router) PathPrefix

func (r *Router) PathPrefix(tpl string) *Route

PathPrefix registers a new route with a matcher for the URL path prefix. See Route.PathPrefix().

func (*Router) Queries

func (r *Router) Queries(pairs ...string) *Route

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 (r *Router) Restricted(restricted bool)

func (*Router) Schemes

func (r *Router) Schemes(schemes ...string) *Route

Schemes registers a new route with a matcher for URL schemes. See Route.Schemes().

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Router) SkipClean

func (r *Router) SkipClean(value bool) *Router

func (*Router) StrictSlash

func (r *Router) StrictSlash(value bool) *Router

func (*Router) Use

func (r *Router) Use(mwf ...func(http.Handler) http.Handler)

func (*Router) UseEncodedPath

func (r *Router) UseEncodedPath() *Router

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL