Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
2f8a70d5
authored
2014-06-11 09:33:35 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
beego: router support param has _
1 parent
7c0d0900
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
5 deletions
tree.go
tree_test.go
tree.go
View file @
2f8a70d
...
...
@@ -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 @
2f8a70d
...
...
@@ -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
Styling with
Markdown
is supported
Attach a file
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 post a comment