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
f7b01aab
Commit
f7b01aab
authored
Jun 10, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
beego: modify the filter sequence
parent
2570f075
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
18 deletions
+26
-18
controller.go
controller.go
+4
-3
parser.go
parser.go
+10
-8
router.go
router.go
+12
-7
No files found.
controller.go
View file @
f7b01aab
...
...
@@ -82,7 +82,7 @@ type ControllerInterface interface {
Render
()
error
XsrfToken
()
string
CheckXsrfCookie
()
bool
HandlerFunc
(
fn
string
)
HandlerFunc
(
fn
string
)
bool
URLMapping
()
}
...
...
@@ -147,11 +147,12 @@ func (c *Controller) Options() {
}
// call function fn
func
(
c
*
Controller
)
HandlerFunc
(
fnname
string
)
{
func
(
c
*
Controller
)
HandlerFunc
(
fnname
string
)
bool
{
if
v
,
ok
:=
c
.
methodMapping
[
fnname
];
ok
{
v
()
return
true
}
else
{
Error
(
"call funcname not exist in the methodMapping: "
+
fnname
)
return
false
}
}
...
...
parser.go
View file @
f7b01aab
...
...
@@ -98,11 +98,6 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat
func
genRouterCode
()
{
os
.
Mkdir
(
path
.
Join
(
AppPath
,
"routers"
),
0755
)
Info
(
"generate router from comments"
)
f
,
err
:=
os
.
Create
(
path
.
Join
(
AppPath
,
"routers"
,
"commentsRouter.go"
))
if
err
!=
nil
{
panic
(
err
)
}
defer
f
.
Close
()
var
globalinfo
string
for
k
,
cList
:=
range
genInfoList
{
for
_
,
c
:=
range
cList
{
...
...
@@ -124,9 +119,16 @@ func genRouterCode() {
}
params
=
strings
.
TrimRight
(
params
,
","
)
+
"}"
}
globalinfo
=
globalinfo
+
fmt
.
Sprintln
(
`beego.GlobalControllerRouter["`
+
k
+
`"] = &beego.ControllerComments{"`
+
strings
.
TrimSpace
(
c
.
Method
)
+
`", "`
+
c
.
Router
+
`", `
+
allmethod
+
", "
+
params
+
"}"
)
globalinfo
=
globalinfo
+
fmt
.
Sprintln
(
`beego.GlobalControllerRouter["`
+
k
+
`"] = append(beego.GlobalControllerRouter["`
+
k
+
`"], beego.ControllerComments{"`
+
strings
.
TrimSpace
(
c
.
Method
)
+
`", "`
+
c
.
Router
+
`", `
+
allmethod
+
", "
+
params
+
"})"
)
}
}
if
globalinfo
!=
""
{
f
,
err
:=
os
.
Create
(
path
.
Join
(
AppPath
,
"routers"
,
"commentsRouter.go"
))
if
err
!=
nil
{
panic
(
err
)
}
defer
f
.
Close
()
f
.
WriteString
(
strings
.
Replace
(
globalRouterTemplate
,
"{{.globalinfo}}"
,
globalinfo
,
-
1
))
}
f
.
WriteString
(
strings
.
Replace
(
globalRouterTemplate
,
"{{.globalinfo}}"
,
globalinfo
,
-
1
))
}
router.go
View file @
f7b01aab
...
...
@@ -559,10 +559,6 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
http
.
Error
(
w
,
"Method Not Allowed"
,
405
)
goto
Admin
}
//static file server
if
serverStaticRouter
(
context
)
{
goto
Admin
}
if
!
context
.
Input
.
IsGet
()
&&
!
context
.
Input
.
IsHead
()
{
if
CopyRequestBody
&&
!
context
.
Input
.
IsUpload
()
{
...
...
@@ -575,6 +571,11 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
goto
Admin
}
//static file server
if
serverStaticRouter
(
context
)
{
goto
Admin
}
if
context
.
Input
.
RunController
!=
nil
&&
context
.
Input
.
RunMethod
!=
""
{
findrouter
=
true
runMethod
=
context
.
Input
.
RunMethod
...
...
@@ -666,6 +667,8 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
}
}
execController
.
URLMapping
()
if
!
w
.
started
{
//exec main logic
switch
runMethod
{
...
...
@@ -684,9 +687,11 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
case
"Options"
:
execController
.
Options
()
default
:
in
:=
make
([]
reflect
.
Value
,
0
)
method
:=
vc
.
MethodByName
(
runMethod
)
method
.
Call
(
in
)
if
!
execController
.
HandlerFunc
(
runMethod
)
{
in
:=
make
([]
reflect
.
Value
,
0
)
method
:=
vc
.
MethodByName
(
runMethod
)
method
.
Call
(
in
)
}
}
//render template
...
...
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