trie

package
v3.3.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2016 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Special Trie implementation for HTTP routing.

This Trie implementation is designed to support strings that includes :param and *splat parameters. Strings that are commonly used to represent the Path in HTTP routing. This implementation also maintain for each Path a map of HTTP Methods associated with the Route.

You probably don't need to use this package directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Match

type Match struct {
	// Same Route as in AddRoute
	Route interface{}
	// map of params matched for this result
	Params map[string]string
}

type Trie

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

func New

func New() *Trie

Instanciate a Trie with an empty node as the root.

func (*Trie) AddRoute

func (t *Trie) AddRoute(httpMethod, pathExp string, route interface{}) error

Insert the route in the Trie following or creating the nodes corresponding to the path.

func (*Trie) Compress

func (t *Trie) Compress()

Reduce the size of the tree, must be done after the last AddRoute.

func (*Trie) FindRoutes

func (t *Trie) FindRoutes(httpMethod, path string) []*Match

Given a path and an http method, return all the matching routes.

func (*Trie) FindRoutesAndPathMatched

func (t *Trie) FindRoutesAndPathMatched(httpMethod, path string) ([]*Match, bool)

Same as FindRoutes, but return in addition a boolean indicating if the path was matched. Useful to return 405

func (*Trie) FindRoutesForPath

func (t *Trie) FindRoutesForPath(path string) []*Match

Given a path, and whatever the http method, return all the matching routes.

Jump to

Keyboard shortcuts

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