Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"net/http"
"github.com/DavidCai1993/routing"
)
var httpHandler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World"))
})
func main() {
router := routing.New()
router.Define("/:type(a|b)/:id(0-9a-f]{24})", httpHandler)
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"}
}
Output:
Index ¶
Examples ¶
Constants ¶
const Version = "1.1.0"
Version is this package's version number.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents a node in the trie tree. In this package, you can only get the root node by the New() func. And then define and match URL with it.
func (*Node) Define ¶
Define defines a URL and some meta infomation (interface{}) on it.
support signatures:
- 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})`