https://github.com/mantyr/prefixtree
Golang Parameterized Prefix Tree
https://github.com/mantyr/prefixtree
params prefixtree router tree
Last synced: 30 days ago
JSON representation
Golang Parameterized Prefix Tree
- Host: GitHub
- URL: https://github.com/mantyr/prefixtree
- Owner: mantyr
- License: mit
- Created: 2019-03-13T18:38:50.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-27T10:57:46.000Z (about 7 years ago)
- Last Synced: 2025-12-17T20:22:28.709Z (4 months ago)
- Topics: params, prefixtree, router, tree
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 5
- Watchers: 4
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Golang Parameterized Prefix Tree
[](https://travis-ci.org/mantyr/prefixtree)
[](http://godoc.org/github.com/mantyr/prefixtree)
[][goreport]
[](LICENSE.md)
This stable version
## Priorities for the selection of values
1. Static Node
2. Params Node
3. CatchAll Node
## Restrictions
1. CatchAll can be only one and only at the insert end
```GO
root.SetString("/path/*filepath*other", "value") // error
root.SetString("/path/*filepath/*other", "value") // error
root.SetString("/path/*filepath/123/*other", "value") // error
root.SetString("/path/*filepath", "value") // OK
```
2. CatchAll has the lowest priority
```GO
root.SetString("/path/123/123", "value1") // OK
root.SetString("/path/:id/123", "value2") // OK
root.SetString("/path/*filepath", "value3") // OK
root.GetString("/path/123/123") // value1
root.GetString("/path/234/123") // value2
root.GetString("/path/123/234") // value3
```
## Installation
$ go get -u github.com/mantyr/prefixtree
## Example
```GO
package main
import (
"github.com/mantyr/prefixtree"
)
func main() {
root := prefixtree.New()
root.SetString("/path/:dir/123", "value1")
root.SetString("/path/:dir/*filepath", "value2")
root.SetString("/path/user_:user", "value3")
root.SetString("/id/:id", "value4")
root.SetString("/id:id", "value5")
root.SetString(":id/:name/123", "value6")
root.SetString("/id:id", "value7") // error: path already in use
root.SetString("/id:id2", "value8")
value, err := root.GetString("/path/123/file.zip")
/*
value.Path = "/path/123/file.zip"
value.Value = "value2"
value.Params["dir"] = "123"
value.Params["filepath"] = "file.zip"
*/
items := View(root)
/*
items = []string{
"^[/][path/]:dir[/][123]=value1"
"^[/][path/]:dir[/]*filepath=value2"
"^[/][path/][user_]:user=value3"
"^[/][id][/]:id=value4"
"^[/][id]:id=value5"
"^[/][id]:id2=value8"
"^:id[/]:name[/123]=value6"
}
*/
}
```
## Author
[Oleg Shevelev][mantyr]
[mantyr]: https://github.com/mantyr
[build_status]: https://travis-ci.org/mantyr/prefixtree
[godoc]: http://godoc.org/github.com/mantyr/prefixtree
[goreport]: https://goreportcard.com/report/github.com/mantyr/prefixtree