Skip to content

stevenle/routetrie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

routetrie

Efficient URL route lookups for Golang

routetrie is an implementation of a trie data structure that can be used for efficient URL route lookups.

Named :params and *wildcard placeholders are supported.

package main

import (
  "github.com/stevenle/routetrie"
)

func main() {
  // Initialize the trie.
  trie := routetrie.NewRouteTrie()

  // Add routes.
  trie.Add("example.com/foo", 1)
  trie.Add("example.com/foo/:bar", 2)
  trie.Add("example.com/foo/:bar/*baz", 3)

  // Find routes.
  trie.Get("example.com/foo")  // => 1, {}
  trie.Get("example.com/foo/bar")  // => 2, {"bar": "bar"}
  trie.Get("example.com/foo/bar/baz/qux")  // => 3, {"bar": "bar", "baz": "baz/qux"}
}

About

Efficient URL route lookups for Golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages