Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
03080b3e
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,发现更多精彩内容 >>
提交
03080b3e
编写于
5月 20, 2014
作者:
A
astaxie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
beego:1.2.0
上级
b45f0b9b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
30 deletion
+26
-30
router.go
router.go
+0
-5
router_test.go
router_test.go
+17
-22
utils/file.go
utils/file.go
+9
-3
未找到文件。
router.go
浏览文件 @
03080b3e
...
...
@@ -797,14 +797,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
}
if
len
(
route
.
params
)
>
0
{
//add url parameters to the query param map
values
:=
r
.
URL
.
Query
()
for
i
,
match
:=
range
matches
[
1
:
]
{
values
.
Add
(
route
.
params
[
i
],
match
)
params
[
route
.
params
[
i
]]
=
match
}
//reassemble query params and add to RawQuery
r
.
URL
.
RawQuery
=
url
.
Values
(
values
)
.
Encode
()
}
runMethod
=
p
.
getRunMethod
(
r
.
Method
,
context
,
route
)
if
runMethod
!=
""
{
...
...
router_test.go
浏览文件 @
03080b3e
...
...
@@ -43,6 +43,15 @@ func (this *TestController) GetUrl() {
this
.
Ctx
.
Output
.
Body
([]
byte
(
this
.
UrlFor
(
".Myext"
)))
}
func
(
t
*
TestController
)
GetParams
()
{
t
.
Ctx
.
WriteString
(
t
.
Ctx
.
Input
.
Query
(
":last"
)
+
"+"
+
t
.
Ctx
.
Input
.
Query
(
":first"
)
+
"+"
+
t
.
Ctx
.
Input
.
Query
(
"learn"
))
}
func
(
t
*
TestController
)
GetManyRouter
()
{
t
.
Ctx
.
WriteString
(
t
.
Ctx
.
Input
.
Query
(
":id"
)
+
t
.
Ctx
.
Input
.
Query
(
":page"
))
}
type
ResStatus
struct
{
Code
int
Msg
string
...
...
@@ -147,21 +156,11 @@ func TestRouteOk(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegistor
()
handler
.
Add
(
"/person/:last/:first"
,
&
TestController
{})
handler
.
Add
(
"/person/:last/:first"
,
&
TestController
{}
,
"get:GetParams"
)
handler
.
ServeHTTP
(
w
,
r
)
lastNameParam
:=
r
.
URL
.
Query
()
.
Get
(
":last"
)
firstNameParam
:=
r
.
URL
.
Query
()
.
Get
(
":first"
)
learnParam
:=
r
.
URL
.
Query
()
.
Get
(
"learn"
)
if
lastNameParam
!=
"anderson"
{
t
.
Errorf
(
"url param set to [%s]; want [%s]"
,
lastNameParam
,
"anderson"
)
}
if
firstNameParam
!=
"thomas"
{
t
.
Errorf
(
"url param set to [%s]; want [%s]"
,
firstNameParam
,
"thomas"
)
}
if
learnParam
!=
"kungfu"
{
t
.
Errorf
(
"url param set to [%s]; want [%s]"
,
learnParam
,
"kungfu"
)
body
:=
w
.
Body
.
String
()
if
body
!=
"anderson+thomas+kungfu"
{
t
.
Errorf
(
"url param set to [%s];"
,
body
)
}
}
...
...
@@ -171,17 +170,13 @@ func TestManyRoute(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegistor
()
handler
.
Add
(
"/beego:id([0-9]+)-:page([0-9]+).html"
,
&
TestController
{})
handler
.
Add
(
"/beego:id([0-9]+)-:page([0-9]+).html"
,
&
TestController
{}
,
"get:GetManyRouter"
)
handler
.
ServeHTTP
(
w
,
r
)
id
:=
r
.
URL
.
Query
()
.
Get
(
":id"
)
page
:=
r
.
URL
.
Query
()
.
Get
(
":page"
)
body
:=
w
.
Body
.
String
()
if
id
!=
"32"
{
t
.
Errorf
(
"url param set to [%s]; want [%s]"
,
id
,
"32"
)
}
if
page
!=
"12"
{
t
.
Errorf
(
"url param set to [%s]; want [%s]"
,
page
,
"12"
)
if
body
!=
"3212"
{
t
.
Errorf
(
"url param set to [%s];"
,
body
)
}
}
...
...
utils/file.go
浏览文件 @
03080b3e
...
...
@@ -64,24 +64,30 @@ func GrepFile(patten string, filename string) (lines []string, err error) {
lines
=
make
([]
string
,
0
)
reader
:=
bufio
.
NewReader
(
fd
)
prefix
:=
""
isLongLine
:=
false
for
{
byteLine
,
isPrefix
,
er
:=
reader
.
ReadLine
()
if
er
!=
nil
&&
er
!=
io
.
EOF
{
return
nil
,
er
}
if
er
==
io
.
EOF
{
break
}
line
:=
string
(
byteLine
)
if
isPrefix
{
prefix
+=
line
continue
}
else
{
isLongLine
=
true
}
line
=
prefix
+
line
if
isLongLine
{
prefix
=
""
}
if
re
.
MatchString
(
line
)
{
lines
=
append
(
lines
,
line
)
}
if
er
==
io
.
EOF
{
break
}
}
return
lines
,
nil
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录