From b89bfe76d0b4c66f60f600b7bfa59d491d3ae017 Mon Sep 17 00:00:00 2001 From: maxin Date: Sat, 30 Jul 2016 21:57:23 +0800 Subject: [PATCH 1/4] update route variables should not have underline --- tree.go | 6 ++++-- tree_test.go | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tree.go b/tree.go index 25b78e50..da7690ea 100644 --- a/tree.go +++ b/tree.go @@ -19,6 +19,7 @@ import ( "regexp" "strings" + "github.com/Maxgis/tree" "github.com/astaxie/beego/context" "github.com/astaxie/beego/utils" ) @@ -467,7 +468,7 @@ func splitPath(key string) []string { // ":name:string" -> true, [:name], ([\w]+) // ":id([0-9]+)" -> true, [:id], ([0-9]+) // ":id([0-9]+)_:name" -> true, [:id :name], ([0-9]+)_(.+) -// "cms_:id_:page.html" -> true, [:id_ :page], cms_(.+)(.+).html +// "cms_:id_:page.html" -> true, [:id :page], cms_(.+)_(.+).html // "cms_:id(.+)_:page.html" -> true, [:id :page], cms_(.+)_(.+).html // "*" -> true, [:splat], "" // "*.*" -> true,[. :path :ext], "" . meaning separator @@ -487,7 +488,7 @@ func splitSegment(key string) (bool, []string, string) { var expt []rune var skipnum int params := []string{} - reg := regexp.MustCompile(`[a-zA-Z0-9_]+`) + reg := regexp.MustCompile(`[a-zA-Z0-9]+`) for i, v := range key { if skipnum > 0 { skipnum-- @@ -574,6 +575,7 @@ func splitSegment(key string) (bool, []string, string) { } params = append(params, ":"+string(param)) } + tree.Print(string(out)) return true, params, string(out) } return false, nil, "" diff --git a/tree_test.go b/tree_test.go index 81ff7edd..df7242cb 100644 --- a/tree_test.go +++ b/tree_test.go @@ -74,6 +74,8 @@ func init() { routers = append(routers, testinfo{"/v1/:v(.+)_cms/ttt_:id(.+)_:page(.+).html", "/v1/2_cms/ttt_123_1.html", map[string]string{":v": "2", ":id": "123", ":page": "1"}}) routers = append(routers, testinfo{"/api/projects/:pid/members/?:mid", "/api/projects/1/members", map[string]string{":pid": "1"}}) routers = append(routers, testinfo{"/api/projects/:pid/members/?:mid", "/api/projects/1/members/2", map[string]string{":pid": "1", ":mid": "2"}}) + routers = append(routers, testinfo{"/page/:id_:page", "/page/12_33", map[string]string{":id": "12", ":page": "33"}}) + routers = append(routers, testinfo{"/page/:id_:page.html", "/page/12_33.html", map[string]string{":id": "12", ":page": "33"}}) } func TestTreeRouters(t *testing.T) { From d5c339530aa9e1492a06fb2eb149e4a7f0c4bc80 Mon Sep 17 00:00:00 2001 From: maxin Date: Sat, 30 Jul 2016 22:05:59 +0800 Subject: [PATCH 2/4] remove debug --- tree.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/tree.go b/tree.go index da7690ea..f93dfa64 100644 --- a/tree.go +++ b/tree.go @@ -19,7 +19,6 @@ import ( "regexp" "strings" - "github.com/Maxgis/tree" "github.com/astaxie/beego/context" "github.com/astaxie/beego/utils" ) @@ -575,7 +574,6 @@ func splitSegment(key string) (bool, []string, string) { } params = append(params, ":"+string(param)) } - tree.Print(string(out)) return true, params, string(out) } return false, nil, "" From 15c048d6ca1f638e05eef447ecba68ddad2d2a8a Mon Sep 17 00:00:00 2001 From: maxin Date: Sat, 30 Jul 2016 22:07:35 +0800 Subject: [PATCH 3/4] update test --- tree_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tree_test.go b/tree_test.go index df7242cb..ab16756e 100644 --- a/tree_test.go +++ b/tree_test.go @@ -74,8 +74,8 @@ func init() { routers = append(routers, testinfo{"/v1/:v(.+)_cms/ttt_:id(.+)_:page(.+).html", "/v1/2_cms/ttt_123_1.html", map[string]string{":v": "2", ":id": "123", ":page": "1"}}) routers = append(routers, testinfo{"/api/projects/:pid/members/?:mid", "/api/projects/1/members", map[string]string{":pid": "1"}}) routers = append(routers, testinfo{"/api/projects/:pid/members/?:mid", "/api/projects/1/members/2", map[string]string{":pid": "1", ":mid": "2"}}) - routers = append(routers, testinfo{"/page/:id_:page", "/page/12_33", map[string]string{":id": "12", ":page": "33"}}) - routers = append(routers, testinfo{"/page/:id_:page.html", "/page/12_33.html", map[string]string{":id": "12", ":page": "33"}}) + routers = append(routers, testinfo{"/view/:id_:page", "/page/12_33", map[string]string{":id": "12", ":page": "33"}}) + routers = append(routers, testinfo{"/view/:id_:page.html", "/page/12_33.html", map[string]string{":id": "12", ":page": "33"}}) } func TestTreeRouters(t *testing.T) { From 6f0a985755110e9dab21cade7f4eec79725b574d Mon Sep 17 00:00:00 2001 From: maxin Date: Sat, 30 Jul 2016 23:14:29 +0800 Subject: [PATCH 4/4] update test --- tree_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tree_test.go b/tree_test.go index ab16756e..a20aed84 100644 --- a/tree_test.go +++ b/tree_test.go @@ -74,8 +74,8 @@ func init() { routers = append(routers, testinfo{"/v1/:v(.+)_cms/ttt_:id(.+)_:page(.+).html", "/v1/2_cms/ttt_123_1.html", map[string]string{":v": "2", ":id": "123", ":page": "1"}}) routers = append(routers, testinfo{"/api/projects/:pid/members/?:mid", "/api/projects/1/members", map[string]string{":pid": "1"}}) routers = append(routers, testinfo{"/api/projects/:pid/members/?:mid", "/api/projects/1/members/2", map[string]string{":pid": "1", ":mid": "2"}}) - routers = append(routers, testinfo{"/view/:id_:page", "/page/12_33", map[string]string{":id": "12", ":page": "33"}}) - routers = append(routers, testinfo{"/view/:id_:page.html", "/page/12_33.html", map[string]string{":id": "12", ":page": "33"}}) + routers = append(routers, testinfo{"/view/:id_:page", "/view/12_33", map[string]string{":id": "12", ":page": "33"}}) + routers = append(routers, testinfo{"/view/:id_:page.html", "/view/12_33.html", map[string]string{":id": "12", ":page": "33"}}) } func TestTreeRouters(t *testing.T) {