Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
2f8a70d5
Commit
2f8a70d5
authored
Jun 11, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
beego: router support param has _
parent
7c0d0900
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
5 deletions
+5
-5
tree.go
tree.go
+1
-1
tree_test.go
tree_test.go
+4
-4
No files found.
tree.go
View file @
2f8a70d5
...
...
@@ -284,7 +284,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
-=
1
...
...
tree_test.go
View file @
2f8a70d5
...
...
@@ -29,8 +29,8 @@ func init() {
routers
=
append
(
routers
,
testinfo
{
"/v1/shop/:name:string"
,
"/v1/shop/nike"
,
map
[
string
]
string
{
":name"
:
"nike"
}})
routers
=
append
(
routers
,
testinfo
{
"/v1/shop/:id([0-9]+)"
,
"/v1/shop//123"
,
map
[
string
]
string
{
":id"
:
"123"
}})
routers
=
append
(
routers
,
testinfo
{
"/v1/shop/:id([0-9]+)_:name"
,
"/v1/shop/123_nike"
,
map
[
string
]
string
{
":id"
:
"123"
,
":name"
:
"nike"
}})
routers
=
append
(
routers
,
testinfo
{
"/v1/shop/:id_cms.html"
,
"/v1/shop/123_cms.html"
,
map
[
string
]
string
{
":id"
:
"123"
}})
routers
=
append
(
routers
,
testinfo
{
"/v1/shop/cms_:id
_:page
.html"
,
"/v1/shop/cms_123_1.html"
,
map
[
string
]
string
{
":id"
:
"123"
,
":page"
:
"1"
}})
routers
=
append
(
routers
,
testinfo
{
"/v1/shop/:id
(.+)
_cms.html"
,
"/v1/shop/123_cms.html"
,
map
[
string
]
string
{
":id"
:
"123"
}})
routers
=
append
(
routers
,
testinfo
{
"/v1/shop/cms_:id
(.+)_:page(.+)
.html"
,
"/v1/shop/cms_123_1.html"
,
map
[
string
]
string
{
":id"
:
"123"
,
":page"
:
"1"
}})
}
func
TestTreeRouters
(
t
*
testing
.
T
)
{
...
...
@@ -113,11 +113,11 @@ func TestSplitSegment(t *testing.T) {
if
!
b
||
len
(
w
)
!=
2
||
w
[
0
]
!=
":id"
||
w
[
1
]
!=
":name"
||
r
!=
`([0-9]+)_(.+)`
{
t
.
Fatal
(
`:id([0-9]+)_:name should return true, [:id :name], '([0-9]+)_(.+)'`
)
}
b
,
w
,
r
=
splitSegment
(
":id_cms.html"
)
b
,
w
,
r
=
splitSegment
(
":id
(.+)
_cms.html"
)
if
!
b
||
len
(
w
)
!=
1
||
w
[
0
]
!=
":id"
||
r
!=
`(.+)_cms.html`
{
t
.
Fatal
(
":id_cms.html should return true, [:id], '(.+)_cms.html'"
)
}
b
,
w
,
r
=
splitSegment
(
"cms_:id
_:page
.html"
)
b
,
w
,
r
=
splitSegment
(
"cms_:id
(.+)_:page(.+)
.html"
)
if
!
b
||
len
(
w
)
!=
2
||
w
[
0
]
!=
":id"
||
w
[
1
]
!=
":page"
||
r
!=
`cms_(.+)_(.+).html`
{
t
.
Fatal
(
":id_cms.html should return true, [:id :page], cms_(.+)_(.+).html"
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment