Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var MatchedRoutePathParam = "$matchedRoutePath" //nolint
MatchedRoutePathParam is the Param name under which the path of the matched route is stored, if Router.SaveMatchedRoutePath is set.
Functions ¶
This section is empty.
Types ¶
type Handle ¶
type Handle func(*nats.Msg, Params, interface{})
Handle is a function that can be registered to a route to handle NATS requests. It has a third parameter for the values of wildcards (path variables).
type Params ¶
type Params []Param
Params is a Param-slice, as returned by the router. The slice is ordered, the first TOPIC parameter is also the first slice value. It is therefore safe to read values by the index.
func (Params) ByName ¶
ByName returns the value of the first Param which key matches the given name. If no matching Param is found, an empty string is returned.
func (Params) MatchedRoutePath ¶
MatchedRoutePath retrieves the path of the matched route. Router.SaveMatchedRoutePath must have been enabled when the respective handler was added, otherwise this function always returns an empty string.
type Router ¶
type Router struct { // If enabled, adds the matched route path onto the request context // before invoking the handler. // The matched route path is only added to handlers of routes that were // registered when this option was enabled. SaveMatchedRoutePath bool // Function to handle panics recovered from NATS handlers. // The handler can be used to keep your server from crashing because of // unrecovered panics. PanicHandler func(*nats.Msg, interface{}) // contains filtered or unexported fields }
Router is a handler which can be used to dispatch requests to different handler functions via configurable routes
func New ¶
func New() *Router
New returns a new initialized Router. Path auto-correction, including trailing slashes, is enabled by default.
func (*Router) Lookup ¶
Lookup allows the manual lookup of a rank + path combo. This is e.g. useful to build a framework around this router. If the path was found, it returns the handle function and the path parameter values.