Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultRecoverFunc(w http.ResponseWriter, req *http.Request)
- func NoopHandler(w http.ResponseWriter, req *http.Request)
- type GlobMux
- type LogHandler
- type MethodMux
- func (m *MethodMux) Handle(pattern string, h http.Handler)
- func (m *MethodMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
- func (m *MethodMux) HandleMethods(pattern string, h http.Handler, methods ...string)
- func (m *MethodMux) Handler(req *http.Request) (h http.Handler, pattern string)
- func (m *MethodMux) ServeHTTP(w http.ResponseWriter, req *http.Request)
- type PanicRecovery
- type PathMux
Constants ¶
const ( Lpath = log.Lshortfile << iota Lmethod LremoteAddr LresponseStatus LcontentLength LstdFlags = log.Ldate | log.Ltime | Lmethod | Lpath | LresponseStatus | LcontentLength )
Variables ¶
var Default http.Handler
Default is a handler that enables panic recovery, logging to standard out, and gzip for all request paths chained after it.
var DefaultPanicRecovery = PanicRecovery{http.HandlerFunc(DefaultRecoverFunc)}
DefaultPanicRecovery is a handler that enables basic panic recovery for all handlers chained after it.
var Gzip = muxchain.ChainedHandlerFunc(gzipHandler)
Gzip is a handler that enables gzip content encoding for all handlers chained after it. It adds the Content-Encoding header to the response.
Functions ¶
func DefaultRecoverFunc ¶
func DefaultRecoverFunc(w http.ResponseWriter, req *http.Request)
func NoopHandler ¶
func NoopHandler(w http.ResponseWriter, req *http.Request)
Types ¶
type GlobMux ¶
type GlobMux struct {
// contains filtered or unexported fields
}
GlobMux muxes patterns with wildcard (*) components.
func (*GlobMux) Handler ¶
Handler accepts a request and returns the appropriate handler for it, along with the pattern it matched. If no appropriate handler is found, the http.NotFoundHandler is returned along with an empty string. GlobMux will choose the handler that matches the most leading path components for the request.
type LogHandler ¶
var DefaultLog *LogHandler
func NewLogHandler ¶
func NewLogHandler(out io.Writer, prefix string, flag int) *LogHandler
func (LogHandler) ServeHTTP ¶
func (l LogHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (LogHandler) ServeHTTPChain ¶
func (l LogHandler) ServeHTTPChain(w http.ResponseWriter, req *http.Request, h ...http.Handler)
type MethodMux ¶
MethodMux allows the caller to specify handlers that are specific to a particular HTTP method
func (*MethodMux) Handle ¶
Handle registers a pattern to a particular handler. The pattern may optionally begin with an HTTP method, followed by a space, e.g.: "GET /homepage". The method may be *, which matches all methods. The method may also be omitted, which is the same as *.
func (*MethodMux) HandleFunc ¶
func (*MethodMux) HandleMethods ¶
HandleMethods registers a pattern to a handler for the given methods.
type PanicRecovery ¶
func (PanicRecovery) ServeHTTP ¶
func (p PanicRecovery) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (PanicRecovery) ServeHTTPChain ¶
func (p PanicRecovery) ServeHTTPChain(w http.ResponseWriter, req *http.Request, h ...http.Handler)
type PathMux ¶
type PathMux struct { *GlobMux // contains filtered or unexported fields }
PathMux muxes patterns by globbing over variable components and adding those as query parameters to the request for handlers.
func (*PathMux) Handle ¶
Handle registers a handler to a pattern. Patterns may conatain variable components specified by a leading colon. For instance, "/order/:id" would map to handlers the same as "/order/*" on a GlobMux, however, handlers will see requests as if the query were "/order/?id=".
Handlers will also match if a partial query is provided. For instance, /order/x will match /order/:id/:name, and the name variable will be empty. Variables are always matched from left to right and the handler with the most matches wins (with static strings beating variables).