Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
72af5ce5
authored
2013-12-12 23:26:28 +0800
by
Pengfei Xue
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add do_filter func to reduce duplicated code
1 parent
aea3c68c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
85 deletions
router.go
router.go
View file @
72af5ce
...
...
@@ -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,18 +454,8 @@ 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
{
goto
Admin
}
}
}
}
if
do_filter
(
BeforeRouter
)
{
goto
Admin
}
//static file server
...
...
@@ -516,18 +524,8 @@ 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
{
goto
Admin
}
}
}
}
if
do_filter
(
AfterStatic
)
{
goto
Admin
}
if
CopyRequestBody
{
...
...
@@ -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
{
goto
Admin
}
}
}
}
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
{
goto
Admin
}
}
}
}
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
{
goto
Admin
}
}
}
}
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
{
goto
Admin
}
}
}
}
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
Styling with
Markdown
is supported
Attach a file
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 post a comment