Documentation ¶
Overview ¶
Package router provides many router utilities, with the primary goals of ease of use, flexibility, and http.Handler interface compliance.
Index ¶
- func DebugRoute(r *mux.Router)
- func Default(routes []Route, opts DefaultOptions) *mux.Router
- func DefaultMiddleware(opts DefaultMiddlewareOptions) []middleware.Middleware
- func DefaultMux(routes []Route, opts DefaultOptions) http.Handler
- func MethodNotAllowed(r *mux.Router)
- func New(routes []Route) *mux.Router
- func NotFound(r *mux.Router)
- func RegisterRoutes(r *mux.Router, routes ...Route)
- type AuthOptions
- type DefaultMiddlewareOptions
- type DefaultOptions
- type DefaultRoutesOptions
- type HealthOptions
- type PrometheusOptions
- type Route
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DebugRoute ¶ added in v0.23.0
DebugRoute sets up the /debug/pprof-related routes.
func Default ¶ added in v0.23.0
func Default(routes []Route, opts DefaultOptions) *mux.Router
Default is the same as New, but adds some default router middleware and routes most services use.
func DefaultMiddleware ¶ added in v0.23.0
func DefaultMiddleware(opts DefaultMiddlewareOptions) []middleware.Middleware
DefaultMiddleware provides a configurable default middleware stack for a router. This middleware is intended only to be used for routes matched by the router. For middleware that's not limited to the router's scope, see middleware.Compose for adding middleware to an http.Handler.
func DefaultMux ¶ added in v0.23.0
func DefaultMux(routes []Route, opts DefaultOptions) http.Handler
DefaultMux creates and returns a Default router, with some some application-wide middleware.
func MethodNotAllowed ¶ added in v0.23.0
MethodNotAllowed adds a MethodNotAllowedHandler to the router, instrumented by New Relic.
func New ¶
New creates a new router, fully compatible with http.Handler. Maintaining this compatibility allows flexibility in choosing a routing library, without sacrificing the ability to use net/http-compatible packages.
func NotFound ¶ added in v0.23.0
NotFound adds a NotFoundHandler to the router, instrumented by New Relic.
func RegisterRoutes ¶ added in v0.23.0
RegisterRoutes provides an easy-to-use way of registering many Routes at once.
Types ¶
type AuthOptions ¶ added in v0.23.0
AuthOptions are options for the authentication middleware.
type DefaultMiddlewareOptions ¶ added in v0.23.0
type DefaultMiddlewareOptions struct { AuthOptions Compress bool CORS bool ETag bool GitCommit string Name string Region string Version string }
DefaultMiddlewareOptions is the configuration struct for router's DefaultMiddleware.
type DefaultOptions ¶ added in v0.23.0
type DefaultOptions struct { // Auth can be set to true to enable query-param-based authentication. Auth bool // Compress can be set to true to enable compression for all responses. Compress bool // CORS can be set to true to enable CORS middleware. CORS bool // ETag, if set to true, will handle etag-related headers accordingly. ETag bool // GitCommit is the git SHA of the app's current git commit. GitCommit string // Name is the application name. Name string // Region is the cluster region where the app is running. Region string // Version is the current version of the application. Version string // Whitelist is a string of regular expression strings, // matching URL paths which should not require authentication. WhiteList []string }
DefaultOptions provides a limited set of options for the Default router.
type DefaultRoutesOptions ¶ added in v0.23.0
type DefaultRoutesOptions struct { HealthOptions PrometheusOptions }
DefaultRoutesOptions provides configuration for the default routes.
type HealthOptions ¶ added in v0.23.0
type HealthOptions struct { // GitCommit is the application's current git commit ID. GitCommit string // Name is the name of the application. Name string // Path is the URL path for the health check route. Path string // Region is the server region where the app is currently running. Region string // Version is the version of the application. There is currently no // standard for this; convention has been semver. Version string }
HealthOptions holds all values needed for the Health route.
type PrometheusOptions ¶ added in v0.23.0
type PrometheusOptions struct { // Path is the URL path for the prometheus metrics route. Path string }
PrometheusOptions exposes options to supply the Prometheus route.
type Route ¶
Route offers a flexible way to add route handling to a given router.
func DefaultRoutes ¶ added in v0.23.0
func DefaultRoutes(opts DefaultRoutesOptions) []Route
DefaultRoutes returns a slice of opinionated routes which most services use.
func GetHealthRoute ¶ added in v0.23.0
func GetHealthRoute(opts HealthOptions) Route
GetHealthRoute returns the health check route.
func GetPrometheusRoute ¶ added in v0.23.0
func GetPrometheusRoute(opts PrometheusOptions) Route
GetPrometheusRoute returns the Prometheus metrics route.