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
f841b596
Commit
f841b596
authored
Dec 15, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #375 from pengfei-xue/devel
add do_filter func to reduce duplicated code
parents
f26c1905
72af5ce5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
79 deletions
+34
-79
router.go
router.go
+34
-79
No files found.
router.go
View file @
f841b596
...
...
@@ -426,6 +426,24 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
context
.
Output
.
Context
=
context
context
.
Output
.
EnableGzip
=
EnableGzip
do_filter
:=
func
(
pos
int
)
(
started
bool
)
{
if
p
.
enableFilter
{
if
l
,
ok
:=
p
.
filters
[
pos
];
ok
{
for
_
,
filterR
:=
range
l
{
if
ok
,
p
:=
filterR
.
ValidRouter
(
r
.
URL
.
Path
);
ok
{
context
.
Input
.
Params
=
p
filterR
.
filterFunc
(
context
)
if
w
.
started
{
return
true
}
}
}
}
}
return
false
}
if
context
.
Input
.
IsWebsocket
()
{
context
.
ResponseWriter
=
rw
context
.
Output
=
beecontext
.
NewOutput
(
rw
)
...
...
@@ -436,19 +454,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
goto
Admin
}
if
p
.
enableFilter
{
if
l
,
ok
:=
p
.
filters
[
BeforeRouter
];
ok
{
for
_
,
filterR
:=
range
l
{
if
ok
,
p
:=
filterR
.
ValidRouter
(
r
.
URL
.
Path
);
ok
{
context
.
Input
.
Params
=
p
filterR
.
filterFunc
(
context
)
if
w
.
started
{
if
do_filter
(
BeforeRouter
)
{
goto
Admin
}
}
}
}
}
//static file server
for
prefix
,
staticDir
:=
range
StaticDir
{
...
...
@@ -516,19 +524,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
context
.
Input
.
CruSession
=
GlobalSessions
.
SessionStart
(
w
,
r
)
}
if
p
.
enableFilter
{
if
l
,
ok
:=
p
.
filters
[
AfterStatic
];
ok
{
for
_
,
filterR
:=
range
l
{
if
ok
,
p
:=
filterR
.
ValidRouter
(
r
.
URL
.
Path
);
ok
{
context
.
Input
.
Params
=
p
filterR
.
filterFunc
(
context
)
if
w
.
started
{
if
do_filter
(
AfterStatic
)
{
goto
Admin
}
}
}
}
}
if
CopyRequestBody
{
context
.
Input
.
Body
()
...
...
@@ -592,19 +590,10 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
r
.
ParseMultipartForm
(
MaxMemory
)
}
//execute middleware filters
if
p
.
enableFilter
{
if
l
,
ok
:=
p
.
filters
[
BeforeExec
];
ok
{
for
_
,
filterR
:=
range
l
{
if
ok
,
p
:=
filterR
.
ValidRouter
(
r
.
URL
.
Path
);
ok
{
context
.
Input
.
Params
=
p
filterR
.
filterFunc
(
context
)
if
w
.
started
{
if
do_filter
(
BeforeExec
)
{
goto
Admin
}
}
}
}
}
//Invoke the request handler
vc
:=
reflect
.
New
(
runrouter
.
controllerType
)
...
...
@@ -747,20 +736,12 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
method
=
vc
.
MethodByName
(
"Finish"
)
method
.
Call
(
in
)
//execute middleware filters
if
p
.
enableFilter
{
if
l
,
ok
:=
p
.
filters
[
AfterExec
];
ok
{
for
_
,
filterR
:=
range
l
{
if
ok
,
p
:=
filterR
.
ValidRouter
(
r
.
URL
.
Path
);
ok
{
context
.
Input
.
Params
=
p
filterR
.
filterFunc
(
context
)
if
w
.
started
{
if
do_filter
(
AfterExec
)
{
goto
Admin
}
}
}
}
}
method
=
vc
.
MethodByName
(
"Destructor"
)
method
.
Call
(
in
)
}
...
...
@@ -797,20 +778,12 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
}
// set find
findrouter
=
true
//execute middleware filters
if
p
.
enableFilter
{
if
l
,
ok
:=
p
.
filters
[
BeforeExec
];
ok
{
for
_
,
filterR
:=
range
l
{
if
ok
,
p
:=
filterR
.
ValidRouter
(
r
.
URL
.
Path
);
ok
{
context
.
Input
.
Params
=
p
filterR
.
filterFunc
(
context
)
if
w
.
started
{
if
do_filter
(
BeforeExec
)
{
goto
Admin
}
}
}
}
}
//parse params
otherurl
:=
requestPath
[
len
(
"/"
+
cName
+
"/"
+
strings
.
ToLower
(
mName
))
:
]
if
len
(
otherurl
)
>
1
{
...
...
@@ -853,22 +826,15 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
}
method
=
vc
.
MethodByName
(
"Finish"
)
method
.
Call
(
in
)
//execute middleware filters
if
p
.
enableFilter
{
if
l
,
ok
:=
p
.
filters
[
AfterExec
];
ok
{
for
_
,
filterR
:=
range
l
{
if
ok
,
p
:=
filterR
.
ValidRouter
(
r
.
URL
.
Path
);
ok
{
context
.
Input
.
Params
=
p
filterR
.
filterFunc
(
context
)
if
w
.
started
{
if
do_filter
(
AfterExec
)
{
goto
Admin
}
}
}
}
}
method
=
vc
.
MethodByName
(
"Destructor"
)
method
.
Call
(
in
)
goto
Admin
}
}
...
...
@@ -883,19 +849,8 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
}
Admin
:
if
p
.
enableFilter
{
if
l
,
ok
:=
p
.
filters
[
FinishRouter
];
ok
{
for
_
,
filterR
:=
range
l
{
if
ok
,
p
:=
filterR
.
ValidRouter
(
r
.
URL
.
Path
);
ok
{
context
.
Input
.
Params
=
p
filterR
.
filterFunc
(
context
)
if
w
.
started
{
break
}
}
}
}
}
do_filter
(
FinishRouter
)
//admin module record QPS
if
EnableAdmin
{
timeend
:=
time
.
Since
(
starttime
)
...
...
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