Documentation
¶
Overview ¶
Package httpx is the thin layer over net/http.ServeMux that gives the server prefixed, middleware-carrying route groups and a record of every registered pattern (for the route-table test and `hatamoto routes`).
Routing rule: the mux is populated once at boot and never changes; anything dynamic (plugin routes) is resolved inside fixed catch-all patterns.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Refuse ¶
func Refuse(w http.ResponseWriter, r *http.Request)
Refuse answers a request the admin refuses to acknowledge (a sealed admin path, an unknown path under the admin prefix) with the site's standard not-found response, so a probe learns nothing. Until a responder is registered it writes a plain 404. It is safe for concurrent use.
func RegisterRefuser ¶
func RegisterRefuser(h http.HandlerFunc)
RegisterRefuser sets the handler Refuse calls. The server registers its themed standard not-found responder at construction. Registration is atomic and the last writer wins.
func WithErrorBodies ¶
WithErrorBodies serves mux, replacing the plain-text 404 and 405 that ServeMux generates with the body written by fail(w, status). The Allow header of a 405 is kept.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group registers patterns under a path prefix, wrapping every handler in the group's middleware.
func NewGroup ¶
func NewGroup(mux registrar, prefix string, mw ...Middleware) *Group
NewGroup returns the root group of mux; all groups derived from it share one route record.
func (*Group) Group ¶
func (g *Group) Group(prefix string, mw ...Middleware) *Group
Group returns a nested group: prefix is appended and mw run inside the parent's middleware.
func (*Group) Handle ¶
Handle registers pattern ("[METHOD ]/path", path relative to the group). A path of "/" matches the group's prefix with or without a trailing slash, and nothing below it. A method is required (a method-less pattern would conflict with the catch-alls). Invalid or conflicting patterns panic at registration.
func (*Group) HandleFunc ¶
func (g *Group) HandleFunc(pattern string, h http.HandlerFunc)
HandleFunc is Handle for a handler function.
type Middleware ¶
Middleware wraps a handler.
func Chain ¶
func Chain(mw ...Middleware) Middleware
Chain composes middleware; the first runs outermost.
type Recorder ¶
type Recorder struct {
http.ResponseWriter
// contains filtered or unexported fields
}
Recorder wraps a ResponseWriter to record the status code and body size. Unwrap exposes the underlying writer to http.ResponseController, so Flush, Hijack and deadlines keep working through it.
func (*Recorder) BytesWritten ¶
BytesWritten is the number of body bytes written.
func (*Recorder) Unwrap ¶
func (r *Recorder) Unwrap() http.ResponseWriter
Unwrap returns the wrapped writer for http.ResponseController.