muxchain: github.com/stephens2424/muxchain/muxchainutil Index | Files

package muxchainutil

import "github.com/stephens2424/muxchain/muxchainutil"

Index

Package Files

globmux.go gzip.go log.go methodmux.go muxchainutil.go panic.go pathmux.go

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.

func DefaultRecoverFunc Uses

func DefaultRecoverFunc(w http.ResponseWriter, req *http.Request)

func NoopHandler Uses

func NoopHandler(w http.ResponseWriter, req *http.Request)

type GlobMux Uses

type GlobMux struct {
    // contains filtered or unexported fields
}

GlobMux muxes patterns with wildcard (*) components.

func NewGlobMux Uses

func NewGlobMux() *GlobMux

NewGlobMux initializes a new GlobMux.

func (*GlobMux) Handle Uses

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

Handle registers a pattern to a handler.

func (*GlobMux) Handler Uses

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 Uses

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

ServeHTTP handles requests with the appropriate globbed handler.

type LogHandler Uses

type LogHandler struct {
    *log.Logger
    // contains filtered or unexported fields
}
var DefaultLog *LogHandler

func NewLogHandler Uses

func NewLogHandler(out io.Writer, prefix string, flag int) *LogHandler

func (LogHandler) ServeHTTP Uses

func (l LogHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (LogHandler) ServeHTTPChain Uses

func (l LogHandler) ServeHTTPChain(w http.ResponseWriter, req *http.Request, h ...http.Handler)

type MethodMux Uses

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 Uses

func NewMethodMux() *MethodMux

NewMethodMux returns a new MethodMux

func (*MethodMux) Handle Uses

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 Uses

func (m *MethodMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

func (*MethodMux) HandleMethods Uses

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 Uses

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 Uses

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

type PanicRecovery Uses

type PanicRecovery struct {
    Recovery http.Handler
}

func (PanicRecovery) ServeHTTP Uses

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

func (PanicRecovery) ServeHTTPChain Uses

func (p PanicRecovery) ServeHTTPChain(w http.ResponseWriter, req *http.Request, h ...http.Handler)

type PathMux Uses

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 Uses

func NewPathMux() *PathMux

NewPathMuxer initializes a PathMux.

func (*PathMux) Handle Uses

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 Uses

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)

Package muxchainutil imports 10 packages (graph) and is imported by 1 packages. Updated 2016-07-16. Refresh now. Tools for package owners.