Web Server路由规则支持中文变量值匹配

This commit is contained in:
john
2018-10-22 17:38:27 +08:00
parent 857378e16c
commit 635adfa84f

View File

@ -275,11 +275,11 @@ func (s *Server) patternToRegRule(rule string) (regrule string, names []string)
switch v[0] {
case ':':
if len(v) > 1 {
regrule += `/([\w\.\-]+)`
regrule += `/(.+)`
names = append(names, v[1:])
break
} else {
regrule += `/[\w\.\-]+`
regrule += `/.+`
break
}
fallthrough
@ -302,7 +302,7 @@ func (s *Server) patternToRegRule(rule string) (regrule string, names []string)
})
s, _ := gregex.ReplaceStringFunc(`\{[\w\.\-]+\}`, v, func(s string) string {
names = append(names, s[1 : len(s) - 1])
return `([\w\.\-]+)`
return `(.+)`
})
if strings.EqualFold(s, v) {
regrule += "/" + v