Documentation ¶
Overview ¶
The registered topic, against which the router matches incoming requests, can contain two types of parameters:
Syntax Type :name named parameter *name catch-all parameter
Named parameters are dynamic topic segments. They match anything until the next '/' or the topic end:
topic: /blog/:category/:post Requests: /blog/go/request-routers match: category="go", post="request-routers" /blog/go/request-routers/ no match, but the router would redirect /blog/go/ no match /blog/go/request-routers/comments no match
The value of parameters is saved as a slice of the Param struct, consisting each of a key and a value. The slice is passed to the Handle func as a third parameter. There are two ways to retrieve the value of a parameter:
// by the name of the parameter user := ps.ByName("user") // defined by :user or *user // by the index of the parameter. This way you can also get the name (key) thirdKey := ps[2].Key // the name of the 3rd parameter thirdValue := ps[2].Value // the value of the 3rd parameter
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HandlerFunc ¶
Handle is a function that can be registered to a route to handle MQTT requests. Like MQTT.HandlerFunc, but has a third parameter for the values of wildcards (topic variables).
type Params ¶
type Params []Param
Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.
type Router ¶
type Router struct { NotFoundHandle HandlerFunc // contains filtered or unexported fields }
Router is a http.Handler which can be used to dispatch requests to different handler functions via configurable routes
func NewRouter ¶
func NewRouter() *Router
New returns a new initialized Router. topic auto-correction, including trailing slashes, is enabled by default.
func (*Router) Handle ¶
func (r *Router) Handle(topic string, handle HandlerFunc)
Handle registers the handler for the given pattern.