Documentation ¶
Overview ¶
Package router trie based on a 256-way trie expressed on the textbook Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne A string symbol table for extended ASCII strings, implemented using a 256-way trie. http://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/TrieST.java.html
Index ¶
- Constants
- func DefaultRootHandler(w http.ResponseWriter, r *http.Request)
- func FromContext(ctx context.Context, param string) string
- func FromContextParam(ctx context.Context, param string) string
- func NotFoundHandler(w http.ResponseWriter, r *http.Request)
- func WithContextParam(ctx context.Context, param, val string) context.Context
- type Err
- type Handler
- type HandlerFunc
- type Match
- type Middleware
- type Mux
- type Router
- func (r *Router) DELETE(path string, handlerFn HandlerFunc)
- func (r *Router) FileServer(path string, root http.Dir)
- func (r *Router) GET(path string, handlerFn HandlerFunc)
- func (r *Router) Handle(method, path string, handler Handler)
- func (r *Router) HandleFunc(method, path string, handlerFn HandlerFunc)
- func (r *Router) NotFoundHandler(handlerFn HandlerFunc)
- func (r *Router) POST(path string, handlerFn HandlerFunc)
- func (r *Router) PUT(path string, handler HandlerFunc)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) WrapperMiddleware(mids ...Middleware)
- type WrapErr
Constants ¶
const R = 256
R extended ASCII
Variables ¶
This section is empty.
Functions ¶
func DefaultRootHandler ¶
func DefaultRootHandler(w http.ResponseWriter, r *http.Request)
DefaultRootHandler hello world handler
func FromContext ¶
FromContext returns value for repective param available in context NOte: deprecated, please use FromContextParam
func FromContextParam ¶
FromContextParam returns value for repective param available in context
func NotFoundHandler ¶
func NotFoundHandler(w http.ResponseWriter, r *http.Request)
NotFoundHandler default not found resource json handler
Types ¶
type Err ¶
type Err struct { Err error `json:"-"` Status int `json:"-"` Type string `json:"type"` Message string `json:"message"` Code string `json:"code,omitempty"` Metadata map[string]string `json:"metadata,omitempty"` }
Err struct containing an error and helper fields
type Handler ¶
type Handler interface {
ServeHTTP(http.ResponseWriter, *http.Request)
}
Handler is a function type like "net/http" Handler
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request)
HandlerFunc is a function type like "net/http" HandlerFunc
func Wrap ¶
func Wrap(h HandlerFunc, middlewares ...Middleware) HandlerFunc
Wrap h with all specified middlewares.
func (HandlerFunc) ServeHTTP ¶
func (fn HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP calls f(w, r)
type Match ¶
type Match struct {
// contains filtered or unexported fields
}
Match wraps an Handler and context
type Middleware ¶
type Middleware func(HandlerFunc) HandlerFunc
Middleware wraps an http.HandlerFunc with additional functionality.
type Mux ¶
type Mux interface { GET(string, HandlerFunc) POST(string, HandlerFunc) PUT(string, HandlerFunc) DELETE(string, HandlerFunc) HandleFunc(string, string, HandlerFunc) ServeHTTP(http.ResponseWriter, *http.Request) WrapperMiddleware(...Middleware) }
Mux interface to expose router struct
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router ..
func (*Router) DELETE ¶
func (r *Router) DELETE(path string, handlerFn HandlerFunc)
DELETE is a shortcut for Handle with method "DELETE"
func (*Router) FileServer ¶
FileServer returns a handler that serves HTTP requests with the contents of the file system rooted at root.
func (*Router) GET ¶
func (r *Router) GET(path string, handlerFn HandlerFunc)
GET is a shortcut for Handle with method "GET"
func (*Router) HandleFunc ¶
func (r *Router) HandleFunc(method, path string, handlerFn HandlerFunc)
HandleFunc registers the handler function for the given pattern.
func (*Router) NotFoundHandler ¶
func (r *Router) NotFoundHandler(handlerFn HandlerFunc)
NotFoundHandler is configuraton method to alow clients to customize NotFoundHandler
func (*Router) POST ¶
func (r *Router) POST(path string, handlerFn HandlerFunc)
POST is a shortcut for Handle with method "POST"
func (*Router) PUT ¶
func (r *Router) PUT(path string, handler HandlerFunc)
PUT is a shortcut for Handle with method "PUT"
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP
func (*Router) WrapperMiddleware ¶
func (r *Router) WrapperMiddleware(mids ...Middleware)
WrapperMiddleware ..
type WrapErr ¶
type WrapErr func(http.ResponseWriter, *http.Request) *Err
WrapErr reduces the repetition of dealing with errors in Handlers returning an error https://blog.golang.org/error-handling-and-go