mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
修复路由变量匹配到'/'字符的问题
This commit is contained in:
@ -275,11 +275,11 @@ func (s *Server) patternToRegRule(rule string) (regrule string, names []string)
|
||||
switch v[0] {
|
||||
case ':':
|
||||
if len(v) > 1 {
|
||||
regrule += `/(.+)`
|
||||
regrule += `/([^/]+)`
|
||||
names = append(names, v[1:])
|
||||
break
|
||||
} else {
|
||||
regrule += `/.+`
|
||||
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 `(.+)`
|
||||
return `([^/]+)`
|
||||
})
|
||||
if strings.EqualFold(s, v) {
|
||||
regrule += "/" + v
|
||||
|
||||
@ -1,16 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gitee.com/johng/gf/g/os/gcron"
|
||||
"gitee.com/johng/gf/g/os/glog"
|
||||
"gitee.com/johng/gf/g/os/gtime"
|
||||
"gitee.com/johng/gf/g"
|
||||
"gitee.com/johng/gf/g/net/ghttp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
start := gtime.Second()
|
||||
gcron.Add("*/5 * * * * ?", func() {
|
||||
glog.Println(gtime.Second() - start)
|
||||
s := g.Server()
|
||||
s.BindHandler("/{class}-{course}/:name/*act", func(r *ghttp.Request){
|
||||
r.Response.Writeln(r.Get("class"))
|
||||
r.Response.Writeln(r.Get("course"))
|
||||
r.Response.Writeln(r.Get("name"))
|
||||
r.Response.Writeln(r.Get("act"))
|
||||
})
|
||||
|
||||
select{}
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
}
|
||||
Reference in New Issue
Block a user