Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
4786fb09
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,发现更多精彩内容 >>
提交
4786fb09
编写于
6月 10, 2014
作者:
A
astaxie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
beego:fix typo NewControllerRegister
上级
fdb5672b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
26 addition
and
26 deletion
+26
-26
app.go
app.go
+1
-1
filter_test.go
filter_test.go
+3
-3
flash_test.go
flash_test.go
+1
-1
namespace.go
namespace.go
+1
-1
router.go
router.go
+2
-2
router_test.go
router_test.go
+18
-18
未找到文件。
app.go
浏览文件 @
4786fb09
...
...
@@ -27,7 +27,7 @@ type App struct {
// NewApp returns a new beego application.
func
NewApp
()
*
App
{
cr
:=
NewControllerRegist
o
r
()
cr
:=
NewControllerRegist
e
r
()
app
:=
&
App
{
Handlers
:
cr
,
Server
:
&
http
.
Server
{}}
return
app
}
...
...
filter_test.go
浏览文件 @
4786fb09
...
...
@@ -21,7 +21,7 @@ var FilterUser = func(ctx *context.Context) {
func
TestFilter
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/person/asta/Xie"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
InsertFilter
(
"/person/:last/:first"
,
BeforeRouter
,
FilterUser
)
handler
.
Add
(
"/person/:last/:first"
,
&
TestController
{})
handler
.
ServeHTTP
(
w
,
r
)
...
...
@@ -40,7 +40,7 @@ var FilterAdminUser = func(ctx *context.Context) {
func
TestPatternTwo
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/admin/"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
InsertFilter
(
"/admin/?:all"
,
BeforeRouter
,
FilterAdminUser
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"i am admin"
{
...
...
@@ -51,7 +51,7 @@ func TestPatternTwo(t *testing.T) {
func
TestPatternThree
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/admin/astaxie"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
InsertFilter
(
"/admin/:all"
,
BeforeRouter
,
FilterAdminUser
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"i am admin"
{
...
...
flash_test.go
浏览文件 @
4786fb09
...
...
@@ -31,7 +31,7 @@ func TestFlashHeader(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
// setup the handler
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Add
(
"/"
,
&
TestFlashController
{},
"get:TestWriteFlash"
)
handler
.
ServeHTTP
(
w
,
r
)
...
...
namespace.go
浏览文件 @
4786fb09
...
...
@@ -26,7 +26,7 @@ type Namespace struct {
func
NewNamespace
(
prefix
string
,
params
...
innnerNamespace
)
*
Namespace
{
ns
:=
&
Namespace
{
prefix
:
prefix
,
handlers
:
NewControllerRegist
o
r
(),
handlers
:
NewControllerRegist
e
r
(),
}
for
_
,
p
:=
range
params
{
p
(
ns
)
...
...
router.go
浏览文件 @
4786fb09
...
...
@@ -75,8 +75,8 @@ type ControllerRegistor struct {
filters
map
[
int
][]
*
FilterRouter
}
// NewControllerRegist
o
r returns a new ControllerRegistor.
func
NewControllerRegist
o
r
()
*
ControllerRegistor
{
// NewControllerRegist
e
r returns a new ControllerRegistor.
func
NewControllerRegist
e
r
()
*
ControllerRegistor
{
return
&
ControllerRegistor
{
routers
:
make
(
map
[
string
]
*
Tree
),
filters
:
make
(
map
[
int
][]
*
FilterRouter
),
...
...
router_test.go
浏览文件 @
4786fb09
...
...
@@ -72,7 +72,7 @@ func (this *JsonController) Get() {
}
func
TestUrlFor
(
t
*
testing
.
T
)
{
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Add
(
"/api/list"
,
&
TestController
{},
"*:List"
)
handler
.
Add
(
"/person/:last/:first"
,
&
TestController
{})
handler
.
AddAuto
(
&
TestController
{})
...
...
@@ -95,7 +95,7 @@ func TestUserFunc(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/api/list"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Add
(
"/api/list"
,
&
TestController
{},
"*:List"
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"i am list"
{
...
...
@@ -107,7 +107,7 @@ func TestPostFunc(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"POST"
,
"/astaxie"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Add
(
"/:name"
,
&
TestController
{})
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"astaxie"
{
...
...
@@ -119,7 +119,7 @@ func TestAutoFunc(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/test/list"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
AddAuto
(
&
TestController
{})
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"i am list"
{
...
...
@@ -131,7 +131,7 @@ func TestAutoFuncParams(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/test/params/2009/11/12"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
AddAuto
(
&
TestController
{})
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"20091112"
{
...
...
@@ -143,7 +143,7 @@ func TestAutoExtFunc(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/test/myext.json"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
AddAuto
(
&
TestController
{})
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"json"
{
...
...
@@ -156,7 +156,7 @@ func TestRouteOk(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/person/anderson/thomas?learn=kungfu"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Add
(
"/person/:last/:first"
,
&
TestController
{},
"get:GetParams"
)
handler
.
ServeHTTP
(
w
,
r
)
body
:=
w
.
Body
.
String
()
...
...
@@ -170,7 +170,7 @@ func TestManyRoute(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/beego32-12.html"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Add
(
"/beego:id([0-9]+)-:page([0-9]+).html"
,
&
TestController
{},
"get:GetManyRouter"
)
handler
.
ServeHTTP
(
w
,
r
)
...
...
@@ -185,7 +185,7 @@ func TestNotFound(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Code
!=
http
.
StatusNotFound
{
...
...
@@ -199,7 +199,7 @@ func TestStatic(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/static/js/jquery.js"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Code
!=
404
{
...
...
@@ -211,7 +211,7 @@ func TestPrepare(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/json/list"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Add
(
"/json/list"
,
&
JsonController
{})
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
`"prepare"`
{
...
...
@@ -223,7 +223,7 @@ func TestAutoPrefix(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/admin/test/list"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
AddAutoPrefix
(
"/admin"
,
&
TestController
{})
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"i am list"
{
...
...
@@ -235,7 +235,7 @@ func TestRouterGet(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/user"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Get
(
"/user"
,
func
(
ctx
*
context
.
Context
)
{
ctx
.
Output
.
Body
([]
byte
(
"Get userlist"
))
})
...
...
@@ -249,7 +249,7 @@ func TestRouterPost(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"POST"
,
"/user/123"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Post
(
"/user/:id"
,
func
(
ctx
*
context
.
Context
)
{
ctx
.
Output
.
Body
([]
byte
(
ctx
.
Input
.
Param
(
":id"
)))
})
...
...
@@ -267,7 +267,7 @@ func TestRouterHandler(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"POST"
,
"/sayhi"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Handler
(
"/sayhi"
,
http
.
HandlerFunc
(
sayhello
))
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"sayhello"
{
...
...
@@ -292,7 +292,7 @@ func (a *AdminController) Get() {
}
func
TestRouterFunc
(
t
*
testing
.
T
)
{
mux
:=
NewControllerRegist
o
r
()
mux
:=
NewControllerRegist
e
r
()
mux
.
Get
(
"/action"
,
beegoFilterFunc
)
mux
.
Post
(
"/action"
,
beegoFilterFunc
)
rw
,
r
:=
testRequest
(
"GET"
,
"/action"
)
...
...
@@ -303,7 +303,7 @@ func TestRouterFunc(t *testing.T) {
}
func
BenchmarkFunc
(
b
*
testing
.
B
)
{
mux
:=
NewControllerRegist
o
r
()
mux
:=
NewControllerRegist
e
r
()
mux
.
Get
(
"/action"
,
beegoFilterFunc
)
rw
,
r
:=
testRequest
(
"GET"
,
"/action"
)
b
.
ResetTimer
()
...
...
@@ -313,7 +313,7 @@ func BenchmarkFunc(b *testing.B) {
}
func
BenchmarkController
(
b
*
testing
.
B
)
{
mux
:=
NewControllerRegist
o
r
()
mux
:=
NewControllerRegist
e
r
()
mux
.
Add
(
"/action"
,
&
AdminController
{})
rw
,
r
:=
testRequest
(
"GET"
,
"/action"
)
b
.
ResetTimer
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录