mux

package
v0.0.0-...-839d480 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: BSD-3-Clause Imports: 3 Imported by: 0

README

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

Documentation

Overview

Package mux implements an HTTP multiplexer/router

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mux

type Mux struct {
	*Node
	// contains filtered or unexported fields
}

Mux implements http.Handler

func New

func New(routes []*Route) *Mux

New returns a new *Mux

func NewWithContext

func NewWithContext(ctx context.Context, routes []*Route) *Mux

NewWithContext returns a new *Mux with ctx

func (*Mux) ServeHTTP

func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP satisfies the http.Handler interface

type Node

type Node struct {
	Path     string
	Handlers map[string]*Route
	// contains filtered or unexported fields
}

Node represents a trie node

func (*Node) Insert

func (n *Node) Insert(r *Route)

Insert inserts a new path in the tree

func (*Node) Search

func (n *Node) Search(urlPath string) *Node

Search searches for a node in the tree

type Route

type Route struct {
	Path, Method string
	Middleware   []func(http.Handler) http.Handler
	Handler      http.Handler
}

Route defines a url path and handler

Jump to

Keyboard shortcuts

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