Documentation
¶
Overview ¶
Package router provides an interface for the HTTP router (serve mux).
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Middleware = container.NewMap[string, func(http.Handler) http.Handler]() //nolint:gochecknoglobals
Middleware contains a map of middlewares, by name. These can by referenced dynamically from your config files.
View Source
var Plugins = container.NewSafeMap[string, NewRouterFunc]() //nolint:gochecknoglobals
Plugins is the registry for Registry plugins.
Functions ¶
This section is empty.
Types ¶
type Middlewares ¶
Middlewares keeps track of a unique list of middleware for an HTTP server.
func (Middlewares) MarshalJSON ¶
func (m Middlewares) MarshalJSON() ([]byte, error)
MarshalJSON no-op.
func (Middlewares) MarshalYAML ¶
func (m Middlewares) MarshalYAML() ([]byte, error)
MarshalYAML no-op.
func (Middlewares) UnmarshalJSON ¶
func (m Middlewares) UnmarshalJSON(data []byte) error
UnmarshalJSON middlware.
func (Middlewares) UnmarshalText ¶
func (m Middlewares) UnmarshalText(data []byte) error
UnmarshalText middleware.
func (Middlewares) UnmarshalYAML ¶
func (m Middlewares) UnmarshalYAML(data *yaml.Node) error
UnmarshalYAML middlware list.
type NewRouterFunc ¶
type NewRouterFunc func() Router
NewRouterFunc can be used to create a new router.
type Router ¶
type Router interface {
http.Handler
Routes
// Handle and HandleFunc adds routes for `pattern` that matches
// all HTTP methods.
Handle(pattern string, h http.Handler)
HandleFunc(pattern string, h http.HandlerFunc)
// Method and MethodFunc adds routes for `pattern` that matches
// the `method` HTTP method.
Method(method, pattern string, h http.Handler)
MethodFunc(method, pattern string, h http.HandlerFunc)
// HTTP-method routing along `pattern`
Connect(pattern string, h http.HandlerFunc)
Delete(pattern string, h http.HandlerFunc)
Get(pattern string, h http.HandlerFunc)
Head(pattern string, h http.HandlerFunc)
Options(pattern string, h http.HandlerFunc)
Patch(pattern string, h http.HandlerFunc)
Post(pattern string, h http.HandlerFunc)
Put(pattern string, h http.HandlerFunc)
Trace(pattern string, h http.HandlerFunc)
// Use appends one or more middlewares onto the Router stack.
Use(middlewares ...func(http.Handler) http.Handler)
// Mount attaches another http.Handler along ./pattern/*
// This can be used to mount extra routers in subpaths.
Mount(pattern string, h http.Handler)
// NotFound defines a handler to respond whenever a route could
// not be found.
NotFound(h http.HandlerFunc)
// MethodNotAllowed defines a handler to respond whenever a method is
// not allowed.
MethodNotAllowed(h http.HandlerFunc)
}
Router is a servermux.
type Routes ¶
type Routes interface {
// Routes returns the routing tree in an easily traversable structure.
Routes() []Route
// Middlewares returns the list of middlewares in use by the router.
Middlewares() []func(http.Handler) http.Handler
}
Routes interface adds two methods for router traversal, which is also used by the `docgen` subpackage to generation documentation for Routers.
Click to show internal directories.
Click to hide internal directories.