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
48cefc67
Commit
48cefc67
authored
Dec 18, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve performance change reflect to interface
parent
079a4113
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
32 deletions
+17
-32
controller.go
controller.go
+2
-0
router.go
router.go
+15
-32
No files found.
controller.go
View file @
48cefc67
...
...
@@ -55,6 +55,8 @@ type ControllerInterface interface {
Options
()
Finish
()
Render
()
error
XsrfToken
()
string
CheckXsrfCookie
()
bool
}
func
(
c
*
Controller
)
Init
(
ctx
*
context
.
Context
,
controllerName
,
actionName
string
,
app
interface
{})
{
...
...
router.go
View file @
48cefc67
...
...
@@ -667,50 +667,45 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
//Invoke the request handler
vc
:=
reflect
.
New
(
runrouter
)
execController
,
ok
:=
vc
.
Interface
()
.
(
ControllerInterface
)
if
!
ok
{
panic
(
"controller is not ControllerInterface"
)
}
//call the controller init function
method
:=
vc
.
MethodByName
(
"Init"
)
in
:=
make
([]
reflect
.
Value
,
4
)
in
[
0
]
=
reflect
.
ValueOf
(
context
)
in
[
1
]
=
reflect
.
ValueOf
(
runrouter
.
Name
())
in
[
2
]
=
reflect
.
ValueOf
(
runMethod
)
in
[
3
]
=
reflect
.
ValueOf
(
vc
.
Interface
())
method
.
Call
(
in
)
execController
.
Init
(
context
,
runrouter
.
Name
(),
runMethod
,
vc
.
Interface
())
//if XSRF is Enable then check cookie where there has any cookie in the request's cookie _csrf
if
EnableXSRF
{
in
=
make
([]
reflect
.
Value
,
0
)
method
=
vc
.
MethodByName
(
"XsrfToken"
)
method
.
Call
(
in
)
execController
.
XsrfToken
()
if
r
.
Method
==
"POST"
||
r
.
Method
==
"DELETE"
||
r
.
Method
==
"PUT"
||
(
r
.
Method
==
"POST"
&&
(
r
.
Form
.
Get
(
"_method"
)
==
"delete"
||
r
.
Form
.
Get
(
"_method"
)
==
"put"
))
{
method
=
vc
.
MethodByName
(
"CheckXsrfCookie"
)
method
.
Call
(
in
)
execController
.
CheckXsrfCookie
()
}
}
//call prepare function
in
=
make
([]
reflect
.
Value
,
0
)
method
=
vc
.
MethodByName
(
"Prepare"
)
method
.
Call
(
in
)
execController
.
Prepare
()
if
!
w
.
started
{
//exec main logic
method
=
vc
.
MethodByName
(
runMethod
)
in
:=
make
([]
reflect
.
Value
,
0
)
method
:=
vc
.
MethodByName
(
runMethod
)
method
.
Call
(
in
)
//render template
if
!
w
.
started
&&
!
context
.
Input
.
IsWebsocket
()
{
if
AutoRender
{
method
=
vc
.
MethodByName
(
"Render"
)
callMethodWithError
(
method
,
in
)
if
err
:=
execController
.
Render
();
err
!=
nil
{
panic
(
err
)
}
}
}
}
// finish all runrouter. release resource
method
=
vc
.
MethodByName
(
"Finish"
)
method
.
Call
(
in
)
execController
.
Finish
()
//execute middleware filters
if
do_filter
(
AfterExec
)
{
...
...
@@ -805,15 +800,3 @@ func (w *responseWriter) WriteHeader(code int) {
w
.
started
=
true
w
.
writer
.
WriteHeader
(
code
)
}
// call method and panic with error if error is in result params
func
callMethodWithError
(
method
reflect
.
Value
,
params
[]
reflect
.
Value
)
{
results
:=
method
.
Call
(
params
)
if
len
(
results
)
>
0
{
for
_
,
result
:=
range
results
{
if
result
.
Type
()
==
errorType
&&
!
result
.
IsNil
()
{
panic
(
result
.
Interface
()
.
(
error
))
}
}
}
}
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