trie

package
v0.0.0-...-81fa0a8 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2014 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package trie implements a variant of http.ServeMux that uses a trie instead of a map.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Domain

type Domain struct {
	Trie
}

Domain serves the trie for a specific domain.

Domains are the handlers registered for each domain within a ServeMux.

func NewDomain

func NewDomain() *Domain

NewDomain creates a new Domain with no handlers registered.

func (*Domain) ServeHTTP

func (d *Domain) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP finds and serves the appropriate handler for the path.

type ServeMux

type ServeMux struct {
	Trie
}

ServeMux serves the tries for all configured domains.

func NewServeMux

func NewServeMux() *ServeMux

NewServeMux creates a new ServeMux with no handlers registered.

func (*ServeMux) Handle

func (s *ServeMux) Handle(pattern string, handler http.Handler)

Handle registers the given handler to be called on requests matching the given pattern. In general, the pattern takes the following form:

<domain>/<path>

Both the domain and the path portions are optional.

func (*ServeMux) HandleFunc

func (s *ServeMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

HandleFunc is like Handle, but it takes a function compatible with http.HandlerFunc.

func (*ServeMux) ServeHTTP

func (s *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP finds the most appropriate domain handler and serves it.

type Trie

type Trie struct {
	Name  string       // path piece
	Child []*Trie      // child tries
	Leaf  http.Handler // handler for this file/dir or nil to use parent
}

A Trie can store a prefix tree of paths or a suffix tree of domains. It is the basis for the Domain and ServeMux type.

func (*Trie) Find

func (t *Trie) Find(paths []string) (int, *Trie)

Find attempts to find the deepest matching child of this Trie with a non-nil Leaf and return the number of path segments required to reach it and the Trie present at that location.

func (*Trie) Insert

func (t *Trie) Insert(paths []string, leaf http.Handler) error

Insert inserts the given handler in the trie at the given path and returns an error if it could not be inserted (usually because it already existed).

Jump to

Keyboard shortcuts

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