You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

37 lines
927 B

package router
import (
"fmt"
"testing"
)
func TestRouter(t *testing.T) {
ns1 := "default"
nsKline := "kline"
router := New()
router.Route(ns1, "/hello/:name", func(ns, path string, ps Params) {
_ = ps.ByName("name")
// fmt.Printf("handle hello: name=%s, ns=%s, path=%s\n", ps.ByName("name"), ns, path)
})
router.Route(nsKline, "/kline/:bar", func(ns, path string, ps Params) {
fmt.Printf("handle kline: bar=%s, ns=%s, path=%s\n", ps.ByName("bar"), ns, path)
})
found := router.Handle(ns1, "/hello/jack")
if !found {
t.Error("not found...")
}
h, p := router.Lookup(nsKline, "/kline/5m")
if h != nil {
h(nsKline, "/kline/5m", p)
}
// start := time.Now().UnixMilli()
// for i := range 10000000 {
// found := router.Handle(ns1, fmt.Sprintf("/hello/sunny%d", i))
// if !found {
// t.Error("not found...")
// }
// }
// fmt.Printf("use %dms\n", time.Now().UnixMilli()-start) // use 2375ms
}