muxchainutil

package
Version: v0.0.0-...-8216302 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2019 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Lpath = log.Lshortfile << iota
	Lmethod
	LremoteAddr
	LresponseStatus
	LcontentLength

	LstdFlags = log.Ldate | log.Ltime | Lmethod | Lpath | LresponseStatus | LcontentLength
)

Variables

View Source
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.

DefaultPanicRecovery is a handler that enables basic panic recovery for all handlers chained after it.

View Source
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 NewGlobMux

func NewGlobMux() *GlobMux

NewGlobMux initializes a new GlobMux.

func (*GlobMux) Handle

func (g *GlobMux) Handle(pattern string, h http.Handler)

Handle registers a pattern to a handler.

func (*GlobMux) Handler

func (g *GlobMux) Handler(req *http.Request) (h http.Handler, pattern string)

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.

func (*GlobMux) ServeHTTP

func (g *GlobMux) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP handles requests with the appropriate globbed handler.

type LogHandler

type LogHandler struct {
	*log.Logger
	// contains filtered or unexported fields
}
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

type MethodMux struct {
	NotFoundHandler http.Handler
	// contains filtered or unexported fields
}

MethodMux allows the caller to specify handlers that are specific to a particular HTTP method

func NewMethodMux

func NewMethodMux() *MethodMux

NewMethodMux returns a new MethodMux

func (*MethodMux) Handle

func (m *MethodMux) Handle(pattern string, h http.Handler)

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 (m *MethodMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

func (*MethodMux) HandleMethods

func (m *MethodMux) HandleMethods(pattern string, h http.Handler, methods ...string)

HandleMethods registers a pattern to a handler for the given methods.

func (*MethodMux) Handler

func (m *MethodMux) Handler(req *http.Request) (h http.Handler, pattern string)

Handler selects a handler for a request. It will first attempt to chose a handler that matches the particular method. If a handler is not found, pattern will be the empty string.

func (*MethodMux) ServeHTTP

func (m *MethodMux) ServeHTTP(w http.ResponseWriter, req *http.Request)

type PanicRecovery

type PanicRecovery struct {
	Recovery http.Handler
}

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 NewPathMux

func NewPathMux() *PathMux

NewPathMux initializes a PathMux.

func (*PathMux) Handle

func (p *PathMux) Handle(pattern string, h http.Handler)

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).

func (*PathMux) ServeHTTP

func (p *PathMux) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP handles requests by adding path variables to the request and forwarding them to the matched handler. (See Handle)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL