Documentation
¶
Overview ¶
Package routing provides the core interfaces and components for HTTP routing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HandleResult ¶
type HandleResult int
HandleResult indicates how a handler responded to a request.
const ( // NotMatched means this handler did not match at all; the Router continues to the next. NotMatched HandleResult = iota // PathMatched means the path matched but the HTTP method did not; the Router should return 405. PathMatched HandleResult = iota // Handled means the request was fully processed; the Router stops immediately. Handled HandleResult = iota )
type HandlerFunc ¶
type HandlerFunc func(w http.ResponseWriter, r *http.Request)
HandlerFunc is a function adapter that satisfies the HttpHandler interface.
func ChainMiddlewares ¶
func ChainMiddlewares(f HandlerFunc, middlewares []MiddlewareFunc) HandlerFunc
ChainMiddlewares wraps f with the given middlewares, outermost first.
func (HandlerFunc) Handle ¶
func (f HandlerFunc) Handle(w http.ResponseWriter, r *http.Request) HandleResult
Handle calls the function itself and returns Handled.
type HttpHandler ¶
type HttpHandler interface {
Handle(w http.ResponseWriter, r *http.Request) HandleResult
}
HttpHandler is the interface implemented by all routing components in the framework.
type MethodHandler ¶
type MethodHandler struct {
// contains filtered or unexported fields
}
MethodHandler forwards a request to the wrapped handler only when the HTTP method matches.
func NewMethodHandler ¶
func NewMethodHandler(method string, wrapped HttpHandler) *MethodHandler
NewMethodHandler creates a MethodHandler that wraps the given handler.
func (*MethodHandler) Handle ¶
func (d *MethodHandler) Handle(w http.ResponseWriter, r *http.Request) HandleResult
Handle implements HttpHandler. Returns PathMatched when the method does not match, or delegates to the wrapped handler when it does.
type MiddlewareFunc ¶
type MiddlewareFunc func(next HandlerFunc) HandlerFunc
MiddlewareFunc wraps a HandlerFunc with additional behaviour (Decorator pattern). Middlewares are applied left-to-right: the first one in the list runs first.
type PathHandler ¶
type PathHandler struct {
// contains filtered or unexported fields
}
PathHandler forwards a request to the wrapped handler only when the URL path matches the pattern. Patterns support {param} syntax, e.g. /api/users/{id}.
func NewPathHandler ¶
func NewPathHandler(pattern string, wrapped HttpHandler) *PathHandler
NewPathHandler creates a PathHandler that wraps the given handler.
func (*PathHandler) Handle ¶
func (d *PathHandler) Handle(w http.ResponseWriter, r *http.Request) HandleResult
Handle implements HttpHandler. Returns NotMatched when the path does not match. On match, extracts path parameters into the request context and delegates to the wrapped handler.