From 8315ada9dbf89d1e80ecdce503f4868ca4987e74 Mon Sep 17 00:00:00 2001 From: john Date: Fri, 26 Oct 2018 11:39:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B7=AF=E7=94=B1=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=8C=B9=E9=85=8D=E5=88=B0'/'=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/net/ghttp/ghttp_server_router.go | 6 +++--- geg/other/test2.go | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/g/net/ghttp/ghttp_server_router.go b/g/net/ghttp/ghttp_server_router.go index 64c0b9849..f2a5a0a36 100644 --- a/g/net/ghttp/ghttp_server_router.go +++ b/g/net/ghttp/ghttp_server_router.go @@ -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 diff --git a/geg/other/test2.go b/geg/other/test2.go index c10973456..ce69175ff 100644 --- a/geg/other/test2.go +++ b/geg/other/test2.go @@ -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() } \ No newline at end of file