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
4786fb09
Commit
4786fb09
authored
Jun 10, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
beego:fix typo NewControllerRegister
parent
fdb5672b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
26 deletions
+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
No files found.
app.go
View file @
4786fb09
...
@@ -27,7 +27,7 @@ type App struct {
...
@@ -27,7 +27,7 @@ type App struct {
// NewApp returns a new beego application.
// NewApp returns a new beego application.
func
NewApp
()
*
App
{
func
NewApp
()
*
App
{
cr
:=
NewControllerRegist
o
r
()
cr
:=
NewControllerRegist
e
r
()
app
:=
&
App
{
Handlers
:
cr
,
Server
:
&
http
.
Server
{}}
app
:=
&
App
{
Handlers
:
cr
,
Server
:
&
http
.
Server
{}}
return
app
return
app
}
}
...
...
filter_test.go
View file @
4786fb09
...
@@ -21,7 +21,7 @@ var FilterUser = func(ctx *context.Context) {
...
@@ -21,7 +21,7 @@ var FilterUser = func(ctx *context.Context) {
func
TestFilter
(
t
*
testing
.
T
)
{
func
TestFilter
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/person/asta/Xie"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/person/asta/Xie"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
InsertFilter
(
"/person/:last/:first"
,
BeforeRouter
,
FilterUser
)
handler
.
InsertFilter
(
"/person/:last/:first"
,
BeforeRouter
,
FilterUser
)
handler
.
Add
(
"/person/:last/:first"
,
&
TestController
{})
handler
.
Add
(
"/person/:last/:first"
,
&
TestController
{})
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
...
@@ -40,7 +40,7 @@ var FilterAdminUser = func(ctx *context.Context) {
...
@@ -40,7 +40,7 @@ var FilterAdminUser = func(ctx *context.Context) {
func
TestPatternTwo
(
t
*
testing
.
T
)
{
func
TestPatternTwo
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/admin/"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/admin/"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
InsertFilter
(
"/admin/?:all"
,
BeforeRouter
,
FilterAdminUser
)
handler
.
InsertFilter
(
"/admin/?:all"
,
BeforeRouter
,
FilterAdminUser
)
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"i am admin"
{
if
w
.
Body
.
String
()
!=
"i am admin"
{
...
@@ -51,7 +51,7 @@ func TestPatternTwo(t *testing.T) {
...
@@ -51,7 +51,7 @@ func TestPatternTwo(t *testing.T) {
func
TestPatternThree
(
t
*
testing
.
T
)
{
func
TestPatternThree
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/admin/astaxie"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/admin/astaxie"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
InsertFilter
(
"/admin/:all"
,
BeforeRouter
,
FilterAdminUser
)
handler
.
InsertFilter
(
"/admin/:all"
,
BeforeRouter
,
FilterAdminUser
)
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"i am admin"
{
if
w
.
Body
.
String
()
!=
"i am admin"
{
...
...
flash_test.go
View file @
4786fb09
...
@@ -31,7 +31,7 @@ func TestFlashHeader(t *testing.T) {
...
@@ -31,7 +31,7 @@ func TestFlashHeader(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
// setup the handler
// setup the handler
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Add
(
"/"
,
&
TestFlashController
{},
"get:TestWriteFlash"
)
handler
.
Add
(
"/"
,
&
TestFlashController
{},
"get:TestWriteFlash"
)
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
...
...
namespace.go
View file @
4786fb09
...
@@ -26,7 +26,7 @@ type Namespace struct {
...
@@ -26,7 +26,7 @@ type Namespace struct {
func
NewNamespace
(
prefix
string
,
params
...
innnerNamespace
)
*
Namespace
{
func
NewNamespace
(
prefix
string
,
params
...
innnerNamespace
)
*
Namespace
{
ns
:=
&
Namespace
{
ns
:=
&
Namespace
{
prefix
:
prefix
,
prefix
:
prefix
,
handlers
:
NewControllerRegist
o
r
(),
handlers
:
NewControllerRegist
e
r
(),
}
}
for
_
,
p
:=
range
params
{
for
_
,
p
:=
range
params
{
p
(
ns
)
p
(
ns
)
...
...
router.go
View file @
4786fb09
...
@@ -75,8 +75,8 @@ type ControllerRegistor struct {
...
@@ -75,8 +75,8 @@ type ControllerRegistor struct {
filters
map
[
int
][]
*
FilterRouter
filters
map
[
int
][]
*
FilterRouter
}
}
// NewControllerRegist
o
r returns a new ControllerRegistor.
// NewControllerRegist
e
r returns a new ControllerRegistor.
func
NewControllerRegist
o
r
()
*
ControllerRegistor
{
func
NewControllerRegist
e
r
()
*
ControllerRegistor
{
return
&
ControllerRegistor
{
return
&
ControllerRegistor
{
routers
:
make
(
map
[
string
]
*
Tree
),
routers
:
make
(
map
[
string
]
*
Tree
),
filters
:
make
(
map
[
int
][]
*
FilterRouter
),
filters
:
make
(
map
[
int
][]
*
FilterRouter
),
...
...
router_test.go
View file @
4786fb09
...
@@ -72,7 +72,7 @@ func (this *JsonController) Get() {
...
@@ -72,7 +72,7 @@ func (this *JsonController) Get() {
}
}
func
TestUrlFor
(
t
*
testing
.
T
)
{
func
TestUrlFor
(
t
*
testing
.
T
)
{
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Add
(
"/api/list"
,
&
TestController
{},
"*:List"
)
handler
.
Add
(
"/api/list"
,
&
TestController
{},
"*:List"
)
handler
.
Add
(
"/person/:last/:first"
,
&
TestController
{})
handler
.
Add
(
"/person/:last/:first"
,
&
TestController
{})
handler
.
AddAuto
(
&
TestController
{})
handler
.
AddAuto
(
&
TestController
{})
...
@@ -95,7 +95,7 @@ func TestUserFunc(t *testing.T) {
...
@@ -95,7 +95,7 @@ func TestUserFunc(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/api/list"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/api/list"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Add
(
"/api/list"
,
&
TestController
{},
"*:List"
)
handler
.
Add
(
"/api/list"
,
&
TestController
{},
"*:List"
)
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"i am list"
{
if
w
.
Body
.
String
()
!=
"i am list"
{
...
@@ -107,7 +107,7 @@ func TestPostFunc(t *testing.T) {
...
@@ -107,7 +107,7 @@ func TestPostFunc(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"POST"
,
"/astaxie"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"POST"
,
"/astaxie"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Add
(
"/:name"
,
&
TestController
{})
handler
.
Add
(
"/:name"
,
&
TestController
{})
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"astaxie"
{
if
w
.
Body
.
String
()
!=
"astaxie"
{
...
@@ -119,7 +119,7 @@ func TestAutoFunc(t *testing.T) {
...
@@ -119,7 +119,7 @@ func TestAutoFunc(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/test/list"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/test/list"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
AddAuto
(
&
TestController
{})
handler
.
AddAuto
(
&
TestController
{})
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"i am list"
{
if
w
.
Body
.
String
()
!=
"i am list"
{
...
@@ -131,7 +131,7 @@ func TestAutoFuncParams(t *testing.T) {
...
@@ -131,7 +131,7 @@ func TestAutoFuncParams(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/test/params/2009/11/12"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/test/params/2009/11/12"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
AddAuto
(
&
TestController
{})
handler
.
AddAuto
(
&
TestController
{})
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"20091112"
{
if
w
.
Body
.
String
()
!=
"20091112"
{
...
@@ -143,7 +143,7 @@ func TestAutoExtFunc(t *testing.T) {
...
@@ -143,7 +143,7 @@ func TestAutoExtFunc(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/test/myext.json"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/test/myext.json"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
AddAuto
(
&
TestController
{})
handler
.
AddAuto
(
&
TestController
{})
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"json"
{
if
w
.
Body
.
String
()
!=
"json"
{
...
@@ -156,7 +156,7 @@ func TestRouteOk(t *testing.T) {
...
@@ -156,7 +156,7 @@ func TestRouteOk(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/person/anderson/thomas?learn=kungfu"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/person/anderson/thomas?learn=kungfu"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Add
(
"/person/:last/:first"
,
&
TestController
{},
"get:GetParams"
)
handler
.
Add
(
"/person/:last/:first"
,
&
TestController
{},
"get:GetParams"
)
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
body
:=
w
.
Body
.
String
()
body
:=
w
.
Body
.
String
()
...
@@ -170,7 +170,7 @@ func TestManyRoute(t *testing.T) {
...
@@ -170,7 +170,7 @@ func TestManyRoute(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/beego32-12.html"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/beego32-12.html"
,
nil
)
w
:=
httptest
.
NewRecorder
()
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
.
Add
(
"/beego:id([0-9]+)-:page([0-9]+).html"
,
&
TestController
{},
"get:GetManyRouter"
)
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
...
@@ -185,7 +185,7 @@ func TestNotFound(t *testing.T) {
...
@@ -185,7 +185,7 @@ func TestNotFound(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Code
!=
http
.
StatusNotFound
{
if
w
.
Code
!=
http
.
StatusNotFound
{
...
@@ -199,7 +199,7 @@ func TestStatic(t *testing.T) {
...
@@ -199,7 +199,7 @@ func TestStatic(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/static/js/jquery.js"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/static/js/jquery.js"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Code
!=
404
{
if
w
.
Code
!=
404
{
...
@@ -211,7 +211,7 @@ func TestPrepare(t *testing.T) {
...
@@ -211,7 +211,7 @@ func TestPrepare(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/json/list"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/json/list"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Add
(
"/json/list"
,
&
JsonController
{})
handler
.
Add
(
"/json/list"
,
&
JsonController
{})
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
`"prepare"`
{
if
w
.
Body
.
String
()
!=
`"prepare"`
{
...
@@ -223,7 +223,7 @@ func TestAutoPrefix(t *testing.T) {
...
@@ -223,7 +223,7 @@ func TestAutoPrefix(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/admin/test/list"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/admin/test/list"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
AddAutoPrefix
(
"/admin"
,
&
TestController
{})
handler
.
AddAutoPrefix
(
"/admin"
,
&
TestController
{})
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"i am list"
{
if
w
.
Body
.
String
()
!=
"i am list"
{
...
@@ -235,7 +235,7 @@ func TestRouterGet(t *testing.T) {
...
@@ -235,7 +235,7 @@ func TestRouterGet(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/user"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/user"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Get
(
"/user"
,
func
(
ctx
*
context
.
Context
)
{
handler
.
Get
(
"/user"
,
func
(
ctx
*
context
.
Context
)
{
ctx
.
Output
.
Body
([]
byte
(
"Get userlist"
))
ctx
.
Output
.
Body
([]
byte
(
"Get userlist"
))
})
})
...
@@ -249,7 +249,7 @@ func TestRouterPost(t *testing.T) {
...
@@ -249,7 +249,7 @@ func TestRouterPost(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"POST"
,
"/user/123"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"POST"
,
"/user/123"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Post
(
"/user/:id"
,
func
(
ctx
*
context
.
Context
)
{
handler
.
Post
(
"/user/:id"
,
func
(
ctx
*
context
.
Context
)
{
ctx
.
Output
.
Body
([]
byte
(
ctx
.
Input
.
Param
(
":id"
)))
ctx
.
Output
.
Body
([]
byte
(
ctx
.
Input
.
Param
(
":id"
)))
})
})
...
@@ -267,7 +267,7 @@ func TestRouterHandler(t *testing.T) {
...
@@ -267,7 +267,7 @@ func TestRouterHandler(t *testing.T) {
r
,
_
:=
http
.
NewRequest
(
"POST"
,
"/sayhi"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"POST"
,
"/sayhi"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegist
o
r
()
handler
:=
NewControllerRegist
e
r
()
handler
.
Handler
(
"/sayhi"
,
http
.
HandlerFunc
(
sayhello
))
handler
.
Handler
(
"/sayhi"
,
http
.
HandlerFunc
(
sayhello
))
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"sayhello"
{
if
w
.
Body
.
String
()
!=
"sayhello"
{
...
@@ -292,7 +292,7 @@ func (a *AdminController) Get() {
...
@@ -292,7 +292,7 @@ func (a *AdminController) Get() {
}
}
func
TestRouterFunc
(
t
*
testing
.
T
)
{
func
TestRouterFunc
(
t
*
testing
.
T
)
{
mux
:=
NewControllerRegist
o
r
()
mux
:=
NewControllerRegist
e
r
()
mux
.
Get
(
"/action"
,
beegoFilterFunc
)
mux
.
Get
(
"/action"
,
beegoFilterFunc
)
mux
.
Post
(
"/action"
,
beegoFilterFunc
)
mux
.
Post
(
"/action"
,
beegoFilterFunc
)
rw
,
r
:=
testRequest
(
"GET"
,
"/action"
)
rw
,
r
:=
testRequest
(
"GET"
,
"/action"
)
...
@@ -303,7 +303,7 @@ func TestRouterFunc(t *testing.T) {
...
@@ -303,7 +303,7 @@ func TestRouterFunc(t *testing.T) {
}
}
func
BenchmarkFunc
(
b
*
testing
.
B
)
{
func
BenchmarkFunc
(
b
*
testing
.
B
)
{
mux
:=
NewControllerRegist
o
r
()
mux
:=
NewControllerRegist
e
r
()
mux
.
Get
(
"/action"
,
beegoFilterFunc
)
mux
.
Get
(
"/action"
,
beegoFilterFunc
)
rw
,
r
:=
testRequest
(
"GET"
,
"/action"
)
rw
,
r
:=
testRequest
(
"GET"
,
"/action"
)
b
.
ResetTimer
()
b
.
ResetTimer
()
...
@@ -313,7 +313,7 @@ func BenchmarkFunc(b *testing.B) {
...
@@ -313,7 +313,7 @@ func BenchmarkFunc(b *testing.B) {
}
}
func
BenchmarkController
(
b
*
testing
.
B
)
{
func
BenchmarkController
(
b
*
testing
.
B
)
{
mux
:=
NewControllerRegist
o
r
()
mux
:=
NewControllerRegist
e
r
()
mux
.
Add
(
"/action"
,
&
AdminController
{})
mux
.
Add
(
"/action"
,
&
AdminController
{})
rw
,
r
:=
testRequest
(
"GET"
,
"/action"
)
rw
,
r
:=
testRequest
(
"GET"
,
"/action"
)
b
.
ResetTimer
()
b
.
ResetTimer
()
...
...
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