{"modulePath":"github.com/mutablelogic/go-server","version":"v1.1.16","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package router\n\nrouter package implements a http.Handler and the ability to register routes on a gateway\n\n## Constants\n\n```go\nconst (\n\tScopeRead = \"github.com/mutablelogic/go-server/router:read\"\n)\n```\n\n## Functions\n\n```go\nfunc NewRoute(host_prefix string, path *regexp.Regexp, fn http.HandlerFunc, methods ...string) *route\n```\n\n```go\nfunc NewWithPlugin(p Plugin, label string) (*router, error)\n```\nCreate a new router task, and register routes from gateways\n\n## Types\n\n```go\ntype Gateway struct {\n\tPrefix      string         `json:\"prefix,omitempty\"`\n\tLabel       string         `json:\"label\"`\n\tDescription string         `json:\"description,omitempty\"`\n\tRoutes      []GatewayRoute `json:\"routes,omitempty\"`\n\tMiddleware  []string       `json:\"middleware,omitempty\"`\n}\n```\n\n```go\ntype GatewayRoute struct {\n\tPath        string   `json:\"path\"`\n\tDescription string   `json:\"description,omitempty\"`\n\tMethods     []string `json:\"methods,omitempty\"`\n\tScopes      []string `json:\"scopes,omitempty\"`\n\tMiddleware  []string `json:\"middleware,omitempty\"`\n}\n```\n\n```go\ntype Middleware struct {\n\t// contains filtered or unexported fields\n}\n```\nMiddleware is a handler which is called before or after the request\n\n```go\nfunc (middleware Middleware) String() string\n```\n\n```go\ntype MiddlewareFn func(http.HandlerFunc) http.HandlerFunc\n```\nMiddlewareFn returns a new http.HandlerFunc given a \"child\" http.HandlerFunc\n\n```go\ntype Plugin struct {\n\ttask.Plugin\n\tPrefix_     types.String `json:\"prefix,omitempty\"`     // Path for serving the router schema, optional\n\tRoutes      []Route      `json:\"routes\"`               // Routes to add to the router, optional (but useless without)\n\tMiddleware_ []string     `json:\"middleware,omitempty\"` // Middleware to add to the router for all routes, optional\n}\n```\nPlugin for the router maps prefixes to gateways\n\n```go\nfunc WithLabel(label string) Plugin\n```\n\n```go\nfunc (p Plugin) Middleware() []string\n```\n\n```go\nfunc (p Plugin) Name() string\n```\n\n```go\nfunc (p Plugin) New(parent context.Context, provider iface.Provider) (iface.Task, error)\n```\nCreate a new logger task with provider of other tasks\n\n```go\nfunc (p Plugin) Prefix() string\n```\n\n```go\nfunc (p Plugin) WithPrefix(prefix string) Plugin\n```\n\n```go\nfunc (p Plugin) WithRoutes(r []Route) Plugin\n```\n\n```go\ntype Route struct {\n\tPrefix      string     `json:\"prefix\"`               // Prefix path for the gateway service\n\tHandler     types.Task `json:\"service\"`              // Service handler\n\tMiddleware_ []string   `json:\"middleware,omitempty\"` // Middleware to add to the router for this route, optional\n}\n```\n\n```go\ntype Router interface {\n\tplugin.Router\n\tAddHandlerEx(string, *regexp.Regexp, http.HandlerFunc, ...string) *route\n}\n```\n\n","path":"github.com/mutablelogic/go-server/pkg/httpserver/router","name":"router","synopsis":"router package implements a http.Handler and the ability to register routes on a gateway","isRedistributable":true}
