URL routing based on trie.
routing
is only used to define and match URLs with some custom meta infomation. And basing on it, you can build your own http router with any additional feature.
go get -u github.com/DavidCai1993/routing
- string:
/hello
- separated string:
/a|b|c
- regex:
/([0-9a-f]{24})
- named parameter:
/:id
- named separated string:
/:id(a|b|c)
- named regex:
/:id([0-9a-f]{24})
API documentation can be found here: https://godoc.org/github.com/DavidCai1993/routing
router := routing.New()
router.Define("/:type(a|b)/:id(0-9a-f]{24})", yourHandler)
callback, params, ok := router.Match("/a/8")
fmt.Println(ok)
// -> true
fmt.Println(callback.(http.Handler))
fmt.Println(params)
// -> map[string]string{"type": "a", "id": "8"}