micro/mux
micro/mux
implements an HTTP multiplexer/router.
Documentation
package mux // import "bitbucket.org/_mikey/micro/mux"
Package mux implements an HTTP multiplexer/router
TYPES
type Mux struct {
*Node
// Has unexported fields.
}
Mux implements http.Handler
func New(routes []*Route) *Mux
New returns a new *Mux
func NewWithContext(ctx context.Context, routes []*Route) *Mux
NewWithContext returns a new *Mux with ctx
func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP satisfies the http.Handler interface
type Node struct {
Path string
Handlers map[string]*Route
// Has unexported fields.
}
Node represents a trie node
func (n *Node) Insert(r *Route)
Insert inserts a new path in the tree
func (n *Node) Search(urlPath string) *Node
Search searches for a node in the tree
type Route struct {
Path, Method string
Middleware []func(http.Handler) http.Handler
Handler http.Handler
}
Route defines a url path and handler
Tests
go test -v
=== RUN TestNewInsertAndSearch
--- PASS: TestNewInsertAndSearch (0.00s)
PASS
ok bitbucket.org/_mikey/micro/mux 0.002s