Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
a5a6a307
B
beego
项目概览
二次元的罪恶王冠
/
beego
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beego
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a5a6a307
编写于
6月 23, 2014
作者:
A
astaxie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
beego: fix the router rule for *
上级
1f6e689e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
14 deletion
+31
-14
router_test.go
router_test.go
+13
-9
tree.go
tree.go
+13
-3
tree_test.go
tree_test.go
+5
-2
未找到文件。
router_test.go
浏览文件 @
a5a6a307
...
...
@@ -79,19 +79,23 @@ func TestUrlFor(t *testing.T) {
handler
:=
NewControllerRegister
()
handler
.
Add
(
"/api/list"
,
&
TestController
{},
"*:List"
)
handler
.
Add
(
"/person/:last/:first"
,
&
TestController
{},
"*:Param"
)
handler
.
AddAuto
(
&
TestController
{})
if
handler
.
UrlFor
(
"TestController.List"
)
!=
"/api/list"
{
Info
(
handler
.
UrlFor
(
"TestController.List"
))
if
a
:=
handler
.
UrlFor
(
"TestController.List"
);
a
!=
"/api/list"
{
Info
(
a
)
t
.
Errorf
(
"TestController.List must equal to /api/list"
)
}
if
handler
.
UrlFor
(
"TestController.Param"
,
":last"
,
"xie"
,
":first"
,
"asta"
)
!=
"/person/xie/asta"
{
t
.
Errorf
(
"TestController.Param must equal to /person/xie/asta, but get "
+
handler
.
UrlFor
(
"TestController.Param"
,
":last"
,
"xie"
,
":first"
,
"asta"
)
)
if
a
:=
handler
.
UrlFor
(
"TestController.Param"
,
":last"
,
"xie"
,
":first"
,
"asta"
);
a
!=
"/person/xie/asta"
{
t
.
Errorf
(
"TestController.Param must equal to /person/xie/asta, but get "
+
a
)
}
if
handler
.
UrlFor
(
"TestController.Myext"
)
!=
"/test/myext"
{
t
.
Errorf
(
"TestController.Myext must equal to /test/myext"
)
}
func
TestUrlFor3
(
t
*
testing
.
T
)
{
handler
:=
NewControllerRegister
()
handler
.
AddAuto
(
&
TestController
{})
if
a
:=
handler
.
UrlFor
(
"TestController.Myext"
);
a
!=
"/test/myext"
{
t
.
Errorf
(
"TestController.Myext must equal to /test/myext, but get "
+
a
)
}
if
handler
.
UrlFor
(
"TestController.GetUrl"
)
!=
"/test/geturl"
{
t
.
Errorf
(
"TestController.GetUrl must equal to /test/geturl
"
)
if
a
:=
handler
.
UrlFor
(
"TestController.GetUrl"
);
a
!=
"/test/geturl"
{
t
.
Errorf
(
"TestController.GetUrl must equal to /test/geturl
, but get "
+
a
)
}
}
...
...
tree.go
浏览文件 @
a5a6a307
...
...
@@ -137,26 +137,36 @@ func (t *Tree) addseg(segments []string, route interface{}, wildcards []string,
}
filterCards
=
append
(
filterCards
,
v
)
}
t
.
leaves
=
append
(
t
.
leaves
,
&
leafInfo
{
runObject
:
route
,
wildcards
:
wildc
ards
,
regexps
:
regexp
.
MustCompile
(
"^"
+
reg
+
"$"
)})
t
.
leaves
=
append
(
t
.
leaves
,
&
leafInfo
{
runObject
:
route
,
wildcards
:
filterC
ards
,
regexps
:
regexp
.
MustCompile
(
"^"
+
reg
+
"$"
)})
}
else
{
t
.
leaves
=
append
(
t
.
leaves
,
&
leafInfo
{
runObject
:
route
,
wildcards
:
wildcards
})
}
}
else
{
seg
:=
segments
[
0
]
iswild
,
params
,
regexpStr
:=
splitSegment
(
seg
)
//for the router /login/*/access match /login/2009/11/access
if
!
iswild
&&
utils
.
InSlice
(
":splat"
,
wildcards
)
{
iswild
=
true
regexpStr
=
seg
}
if
iswild
{
if
t
.
wildcard
==
nil
{
t
.
wildcard
=
NewTree
()
}
if
regexpStr
!=
""
{
if
reg
==
""
{
rr
:=
""
for
_
,
w
:=
range
wildcards
{
if
w
==
"."
||
w
==
":"
{
continue
}
regexpStr
=
"([^/]+)/"
+
regexpStr
if
w
==
":splat"
{
rr
=
rr
+
"(.+)/"
}
else
{
rr
=
rr
+
"([^/]+)/"
}
}
regexpStr
=
rr
+
regexpStr
}
else
{
regexpStr
=
"/"
+
regexpStr
}
...
...
tree_test.go
浏览文件 @
a5a6a307
...
...
@@ -19,6 +19,9 @@ func init() {
routers
=
append
(
routers
,
testinfo
{
"/customer/login"
,
"/customer/login.json"
,
map
[
string
]
string
{
":ext"
:
"json"
}})
routers
=
append
(
routers
,
testinfo
{
"/*"
,
"/customer/123"
,
map
[
string
]
string
{
":splat"
:
"customer/123"
}})
routers
=
append
(
routers
,
testinfo
{
"/*"
,
"/customer/2009/12/11"
,
map
[
string
]
string
{
":splat"
:
"customer/2009/12/11"
}})
routers
=
append
(
routers
,
testinfo
{
"/aa/*/bb"
,
"/aa/2009/bb"
,
map
[
string
]
string
{
":splat"
:
"2009"
}})
routers
=
append
(
routers
,
testinfo
{
"/cc/*/dd"
,
"/cc/2009/11/dd"
,
map
[
string
]
string
{
":splat"
:
"2009/11"
}})
routers
=
append
(
routers
,
testinfo
{
"/ee/:year/*/ff"
,
"/ee/2009/11/ff"
,
map
[
string
]
string
{
":year"
:
"2009"
,
":splat"
:
"11"
}})
routers
=
append
(
routers
,
testinfo
{
"/*.*"
,
"/nice/api.json"
,
map
[
string
]
string
{
":path"
:
"nice/api"
,
":ext"
:
"json"
}})
routers
=
append
(
routers
,
testinfo
{
"/:name/*.*"
,
"/nice/api.json"
,
map
[
string
]
string
{
":name"
:
"nice"
,
":path"
:
"api"
,
":ext"
:
"json"
}})
routers
=
append
(
routers
,
testinfo
{
"/:name/test/*.*"
,
"/nice/test/api.json"
,
map
[
string
]
string
{
":name"
:
"nice"
,
":path"
:
"api"
,
":ext"
:
"json"
}})
...
...
@@ -47,9 +50,9 @@ func TestTreeRouters(t *testing.T) {
if
r
.
params
!=
nil
{
for
k
,
v
:=
range
r
.
params
{
if
vv
,
ok
:=
param
[
k
];
!
ok
{
t
.
Fatal
(
r
.
url
+
r
.
requesturl
+
" get param empty:"
+
k
)
t
.
Fatal
(
r
.
url
+
" "
+
r
.
requesturl
+
" get param empty:"
+
k
)
}
else
if
vv
!=
v
{
t
.
Fatal
(
r
.
url
+
" "
+
r
.
requesturl
+
" should be:"
+
v
+
" get param:"
+
vv
)
t
.
Fatal
(
r
.
url
+
"
"
+
r
.
requesturl
+
" should be:"
+
v
+
" get param:"
+
vv
)
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录