예제 #1
0
func BenchmarkUserRegexp(b *testing.B) {
	b.StopTimer()
	//pattern := "/user/{action}/{arg}/"
	//pattern := "^/user(/(?P<action>[[:alnum:]]+)/(?P<arg>[[:alnum:]]+))?"
	pattern := "^/user/(?P<action>[[:alnum:]]+)/(?P<arg>[[:alnum:]]+)"
	input := "/user/view/1"

	re, err := pathexp.RegexpCompile(pattern)
	if err != nil {
		b.Errorf("pattern compile fail: %s; pattern=%s \n", err, pattern)
		return
	}
	// matched, data := re.Match(input)
	// b.Log(matched, data)
	// if !matched || data["action"] != "view" || data["arg"] != "1" {
	// 	b.Error("Match fail", matched, data)
	// 	return
	// }

	//var m pathexp.Matcher = re

	b.StartTimer()
	for i := 0; i < b.N; i++ {
		re.Match(input)
	}

}
예제 #2
0
파일: route.go 프로젝트: jango2015/wk
// Regexp match with regexp
func (r *RouteTable) Regexp(method, path string) *RouteRule {
	exp, err := pathexp.RegexpCompile(path)
	if err != nil {
		panic(err)
	}

	rule := &RouteRule{
		Pattern: path,
		Method:  method,
		re:      exp,
	}
	r.Routes = append(r.Routes, rule)
	return rule
}