*any/:name路由匹配路由改进支持不带名字的*/:路由规则

This commit is contained in:
john
2018-08-24 18:33:28 +08:00
parent 6c4cf446a0
commit 0af28470aa
3 changed files with 23 additions and 1 deletions

2
TODO
View File

@ -20,7 +20,6 @@ ghttp.Server增加Ip访问控制功能(DenyIps&AllowIps)
ghttp路由功能增加分组路由特性
解决glog串日志情况
ghttp增加返回数据压缩机制
*any模糊匹配路由改进支持不带名字的*路由规则;
检查windows下的平滑重启失效问题
gview中的template标签失效问题
ghttp静态文件服务改进(特别是403返回状态的修改)
@ -60,3 +59,4 @@ DONE:
30. gpage分页增加对自定义后缀的支持如:2.html, 2.php等等
31. gvalid包增加struct tag的校验规则、自定义错误提示信息绑定的支持特性
32. 增加文件缓存包可根据fsnotify机制进行缓存更新
33. *any/:name路由匹配路由改进支持不带名字的*/:路由规则;

View File

@ -275,6 +275,9 @@ func (s *Server) patternToRegRule(rule string) (regrule string, names []string)
regrule += `/([\w\.\-]+)`
names = append(names, v[1:])
break
} else {
regrule += `/[\w\.\-]+`
break
}
fallthrough
case '*':
@ -282,6 +285,9 @@ func (s *Server) patternToRegRule(rule string) (regrule string, names []string)
regrule += `/{0,1}(.*)`
names = append(names, v[1:])
break
} else {
regrule += `/{0,1}.*`
break
}
fallthrough
default:

View File

@ -0,0 +1,16 @@
package main
import (
"gitee.com/johng/gf/g"
"gitee.com/johng/gf/g/net/ghttp"
)
// 试试模糊匹配规则不带名称会怎么样
func main() {
s := g.Server()
s.BindHandler("/hello/*", func(r *ghttp.Request){
r.Response.Writeln("哈喽世界!")
})
s.SetPort(8199)
s.Run()
}