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
2570f075
authored
2014-06-09 17:46:13 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
beego:change ControllerComments exported
1 parent
21cb8ea4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
17 deletions
controller.go
parser.go
router.go
controller.go
View file @
2570f07
...
...
@@ -40,10 +40,10 @@ var (
// store the comment for the controller method
type
ControllerComments
struct
{
m
ethod
string
r
outer
string
a
llowHTTPMethods
[]
string
p
arams
[]
map
[
string
]
string
M
ethod
string
R
outer
string
A
llowHTTPMethods
[]
string
P
arams
[]
map
[
string
]
string
}
// Controller defines some basic http request handler operations, such as
...
...
parser.go
View file @
2570f07
...
...
@@ -69,23 +69,23 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat
}
key
:=
pkgpath
+
":"
+
controllerName
cc
:=
ControllerComments
{}
cc
.
m
ethod
=
funcName
cc
.
r
outer
=
e1
[
0
]
cc
.
M
ethod
=
funcName
cc
.
R
outer
=
e1
[
0
]
if
len
(
e1
)
==
2
&&
e1
[
1
]
!=
""
{
e1
=
strings
.
SplitN
(
e1
[
1
],
" "
,
2
)
if
len
(
e1
)
>=
1
{
cc
.
a
llowHTTPMethods
=
strings
.
Split
(
strings
.
Trim
(
e1
[
0
],
"[]"
),
","
)
cc
.
A
llowHTTPMethods
=
strings
.
Split
(
strings
.
Trim
(
e1
[
0
],
"[]"
),
","
)
}
else
{
cc
.
allowHTTPMethods
=
append
(
cc
.
a
llowHTTPMethods
,
"get"
)
cc
.
AllowHTTPMethods
=
append
(
cc
.
A
llowHTTPMethods
,
"get"
)
}
}
else
{
cc
.
allowHTTPMethods
=
append
(
cc
.
a
llowHTTPMethods
,
"get"
)
cc
.
AllowHTTPMethods
=
append
(
cc
.
A
llowHTTPMethods
,
"get"
)
}
if
len
(
e1
)
==
2
&&
e1
[
1
]
!=
""
{
keyval
:=
strings
.
Split
(
strings
.
Trim
(
e1
[
1
],
"[]"
),
" "
)
for
_
,
kv
:=
range
keyval
{
kk
:=
strings
.
Split
(
kv
,
":"
)
cc
.
params
=
append
(
cc
.
p
arams
,
map
[
string
]
string
{
strings
.
Join
(
kk
[
:
len
(
kk
)
-
1
],
":"
)
:
kk
[
len
(
kk
)
-
1
]})
cc
.
Params
=
append
(
cc
.
P
arams
,
map
[
string
]
string
{
strings
.
Join
(
kk
[
:
len
(
kk
)
-
1
],
":"
)
:
kk
[
len
(
kk
)
-
1
]})
}
}
genInfoList
[
key
]
=
append
(
genInfoList
[
key
],
cc
)
...
...
@@ -107,25 +107,25 @@ func genRouterCode() {
for
k
,
cList
:=
range
genInfoList
{
for
_
,
c
:=
range
cList
{
allmethod
:=
"nil"
if
len
(
c
.
a
llowHTTPMethods
)
>
0
{
if
len
(
c
.
A
llowHTTPMethods
)
>
0
{
allmethod
=
"[]string{"
for
_
,
m
:=
range
c
.
a
llowHTTPMethods
{
for
_
,
m
:=
range
c
.
A
llowHTTPMethods
{
allmethod
+=
`"`
+
m
+
`",`
}
allmethod
=
strings
.
TrimRight
(
allmethod
,
","
)
+
"}"
}
params
:=
"nil"
if
len
(
c
.
p
arams
)
>
0
{
if
len
(
c
.
P
arams
)
>
0
{
params
=
"[]map[string]string{"
for
_
,
p
:=
range
c
.
p
arams
{
for
_
,
p
:=
range
c
.
P
arams
{
for
k
,
v
:=
range
p
{
params
=
params
+
`map[string]string{`
+
k
+
`:"`
+
v
+
`"},`
}
}
params
=
strings
.
TrimRight
(
params
,
","
)
+
"}"
}
globalinfo
=
globalinfo
+
fmt
.
Sprintln
(
`beego.GlobalControllerRouter["`
+
k
+
`"] = &ControllerComments{"`
+
strings
.
TrimSpace
(
c
.
method
)
+
`", "`
+
c
.
r
outer
+
`", `
+
allmethod
+
", "
+
params
+
"}"
)
globalinfo
=
globalinfo
+
fmt
.
Sprintln
(
`beego.GlobalControllerRouter["`
+
k
+
`"] = &
beego.
ControllerComments{"`
+
strings
.
TrimSpace
(
c
.
Method
)
+
`", "`
+
c
.
R
outer
+
`", `
+
allmethod
+
", "
+
params
+
"}"
)
}
}
f
.
WriteString
(
strings
.
Replace
(
globalRouterTemplate
,
"{{.globalinfo}}"
,
globalinfo
,
-
1
))
...
...
router.go
View file @
2570f07
...
...
@@ -185,7 +185,7 @@ func (p *ControllerRegistor) Include(cList ...ControllerInterface) {
key
:=
t
.
PkgPath
()
+
":"
+
t
.
Name
()
if
comm
,
ok
:=
GlobalControllerRouter
[
key
];
ok
{
for
_
,
a
:=
range
comm
{
p
.
Add
(
a
.
router
,
c
,
strings
.
Join
(
a
.
allowHTTPMethods
,
","
)
+
":"
+
a
.
m
ethod
)
p
.
Add
(
a
.
Router
,
c
,
strings
.
Join
(
a
.
AllowHTTPMethods
,
","
)
+
":"
+
a
.
M
ethod
)
}
}
}
...
...
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