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
3ebf2751
Commit
3ebf2751
authored
Jan 03, 2016
by
JessonChan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed camel style name
parent
ee2322e8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
37 deletions
+36
-37
router.go
router.go
+36
-37
No files found.
router.go
View file @
3ebf2751
...
@@ -391,14 +391,14 @@ func (p *ControllerRegister) AddAutoPrefix(prefix string, c ControllerInterface)
...
@@ -391,14 +391,14 @@ func (p *ControllerRegister) AddAutoPrefix(prefix string, c ControllerInterface)
route
.
controllerType
=
ct
route
.
controllerType
=
ct
pattern
:=
path
.
Join
(
prefix
,
strings
.
ToLower
(
controllerName
),
strings
.
ToLower
(
rt
.
Method
(
i
)
.
Name
),
"*"
)
pattern
:=
path
.
Join
(
prefix
,
strings
.
ToLower
(
controllerName
),
strings
.
ToLower
(
rt
.
Method
(
i
)
.
Name
),
"*"
)
patternInit
:=
path
.
Join
(
prefix
,
controllerName
,
rt
.
Method
(
i
)
.
Name
,
"*"
)
patternInit
:=
path
.
Join
(
prefix
,
controllerName
,
rt
.
Method
(
i
)
.
Name
,
"*"
)
pattern
f
ix
:=
path
.
Join
(
prefix
,
strings
.
ToLower
(
controllerName
),
strings
.
ToLower
(
rt
.
Method
(
i
)
.
Name
))
pattern
F
ix
:=
path
.
Join
(
prefix
,
strings
.
ToLower
(
controllerName
),
strings
.
ToLower
(
rt
.
Method
(
i
)
.
Name
))
pattern
f
ixInit
:=
path
.
Join
(
prefix
,
controllerName
,
rt
.
Method
(
i
)
.
Name
)
pattern
F
ixInit
:=
path
.
Join
(
prefix
,
controllerName
,
rt
.
Method
(
i
)
.
Name
)
route
.
pattern
=
pattern
route
.
pattern
=
pattern
for
_
,
m
:=
range
HTTPMETHOD
{
for
_
,
m
:=
range
HTTPMETHOD
{
p
.
addToRouter
(
m
,
pattern
,
route
)
p
.
addToRouter
(
m
,
pattern
,
route
)
p
.
addToRouter
(
m
,
patternInit
,
route
)
p
.
addToRouter
(
m
,
patternInit
,
route
)
p
.
addToRouter
(
m
,
pattern
f
ix
,
route
)
p
.
addToRouter
(
m
,
pattern
F
ix
,
route
)
p
.
addToRouter
(
m
,
pattern
f
ixInit
,
route
)
p
.
addToRouter
(
m
,
pattern
F
ixInit
,
route
)
}
}
}
}
}
}
...
@@ -504,12 +504,12 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin
...
@@ -504,12 +504,12 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin
if
find
{
if
find
{
if
l
.
regexps
==
nil
{
if
l
.
regexps
==
nil
{
if
len
(
l
.
wildcards
)
==
0
{
if
len
(
l
.
wildcards
)
==
0
{
return
true
,
strings
.
Replace
(
url
,
"/"
+
urlPlaceholder
,
""
,
1
)
+
to
u
rl
(
params
)
return
true
,
strings
.
Replace
(
url
,
"/"
+
urlPlaceholder
,
""
,
1
)
+
to
U
rl
(
params
)
}
}
if
len
(
l
.
wildcards
)
==
1
{
if
len
(
l
.
wildcards
)
==
1
{
if
v
,
ok
:=
params
[
l
.
wildcards
[
0
]];
ok
{
if
v
,
ok
:=
params
[
l
.
wildcards
[
0
]];
ok
{
delete
(
params
,
l
.
wildcards
[
0
])
delete
(
params
,
l
.
wildcards
[
0
])
return
true
,
strings
.
Replace
(
url
,
urlPlaceholder
,
v
,
1
)
+
to
u
rl
(
params
)
return
true
,
strings
.
Replace
(
url
,
urlPlaceholder
,
v
,
1
)
+
to
U
rl
(
params
)
}
}
return
false
,
""
return
false
,
""
}
}
...
@@ -518,7 +518,7 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin
...
@@ -518,7 +518,7 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin
if
e
,
isok
:=
params
[
":ext"
];
isok
{
if
e
,
isok
:=
params
[
":ext"
];
isok
{
delete
(
params
,
":path"
)
delete
(
params
,
":path"
)
delete
(
params
,
":ext"
)
delete
(
params
,
":ext"
)
return
true
,
strings
.
Replace
(
url
,
urlPlaceholder
,
p
+
"."
+
e
,
-
1
)
+
to
u
rl
(
params
)
return
true
,
strings
.
Replace
(
url
,
urlPlaceholder
,
p
+
"."
+
e
,
-
1
)
+
to
U
rl
(
params
)
}
}
}
}
}
}
...
@@ -539,7 +539,7 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin
...
@@ -539,7 +539,7 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin
return
false
,
""
return
false
,
""
}
}
}
}
return
true
,
url
+
to
u
rl
(
params
)
return
true
,
url
+
to
U
rl
(
params
)
}
}
var
i
int
var
i
int
var
startreg
bool
var
startreg
bool
...
@@ -566,7 +566,7 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin
...
@@ -566,7 +566,7 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin
for
_
,
p
:=
range
ps
{
for
_
,
p
:=
range
ps
{
url
=
strings
.
Replace
(
url
,
urlPlaceholder
,
p
,
1
)
url
=
strings
.
Replace
(
url
,
urlPlaceholder
,
p
,
1
)
}
}
return
true
,
url
+
to
u
rl
(
params
)
return
true
,
url
+
to
U
rl
(
params
)
}
}
}
}
}
}
...
@@ -597,10 +597,10 @@ func (p *ControllerRegister) execFilter(context *beecontext.Context, pos int, ur
...
@@ -597,10 +597,10 @@ func (p *ControllerRegister) execFilter(context *beecontext.Context, pos int, ur
// Implement http.Handler interface.
// Implement http.Handler interface.
func
(
p
*
ControllerRegister
)
ServeHTTP
(
rw
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
(
p
*
ControllerRegister
)
ServeHTTP
(
rw
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
start
t
ime
:=
time
.
Now
()
start
T
ime
:=
time
.
Now
()
var
(
var
(
run
r
outer
reflect
.
Type
run
R
outer
reflect
.
Type
find
r
outer
bool
find
R
outer
bool
runMethod
string
runMethod
string
routerInfo
*
controllerInfo
routerInfo
*
controllerInfo
)
)
...
@@ -620,7 +620,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
...
@@ -620,7 +620,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
urlPath
=
r
.
URL
.
Path
urlPath
=
r
.
URL
.
Path
}
}
// filter wrong httpmethod
// filter wrong http
method
if
_
,
ok
:=
HTTPMETHOD
[
r
.
Method
];
!
ok
{
if
_
,
ok
:=
HTTPMETHOD
[
r
.
Method
];
!
ok
{
http
.
Error
(
rw
,
"Method Not Allowed"
,
405
)
http
.
Error
(
rw
,
"Method Not Allowed"
,
405
)
goto
Admin
goto
Admin
...
@@ -633,7 +633,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
...
@@ -633,7 +633,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
serverStaticRouter
(
context
)
serverStaticRouter
(
context
)
if
context
.
ResponseWriter
.
Started
{
if
context
.
ResponseWriter
.
Started
{
find
r
outer
=
true
find
R
outer
=
true
goto
Admin
goto
Admin
}
}
...
@@ -662,7 +662,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
...
@@ -662,7 +662,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
goto
Admin
goto
Admin
}
}
if
!
find
r
outer
{
if
!
find
R
outer
{
httpMethod
:=
r
.
Method
httpMethod
:=
r
.
Method
if
httpMethod
==
"POST"
&&
context
.
Input
.
Query
(
"_method"
)
==
"PUT"
{
if
httpMethod
==
"POST"
&&
context
.
Input
.
Query
(
"_method"
)
==
"PUT"
{
httpMethod
=
"PUT"
httpMethod
=
"PUT"
...
@@ -674,10 +674,9 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
...
@@ -674,10 +674,9 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
runObject
:=
t
.
Match
(
urlPath
,
context
)
runObject
:=
t
.
Match
(
urlPath
,
context
)
if
r
,
ok
:=
runObject
.
(
*
controllerInfo
);
ok
{
if
r
,
ok
:=
runObject
.
(
*
controllerInfo
);
ok
{
routerInfo
=
r
routerInfo
=
r
find
r
outer
=
true
find
R
outer
=
true
if
splat
:=
context
.
Input
.
Param
(
":splat"
);
splat
!=
""
{
if
splat
:=
context
.
Input
.
Param
(
":splat"
);
splat
!=
""
{
splatlist
:=
strings
.
Split
(
splat
,
"/"
)
for
k
,
v
:=
range
strings
.
Split
(
splat
,
"/"
)
{
for
k
,
v
:=
range
splatlist
{
context
.
Input
.
SetParam
(
strconv
.
Itoa
(
k
),
v
)
context
.
Input
.
SetParam
(
strconv
.
Itoa
(
k
),
v
)
}
}
}
}
...
@@ -687,12 +686,12 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
...
@@ -687,12 +686,12 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
}
}
//if no matches to url, throw a not found exception
//if no matches to url, throw a not found exception
if
!
find
r
outer
{
if
!
find
R
outer
{
exception
(
"404"
,
context
)
exception
(
"404"
,
context
)
goto
Admin
goto
Admin
}
}
if
find
r
outer
{
if
find
R
outer
{
//execute middleware filters
//execute middleware filters
if
p
.
execFilter
(
context
,
BeforeExec
,
urlPath
)
{
if
p
.
execFilter
(
context
,
BeforeExec
,
urlPath
)
{
goto
Admin
goto
Admin
...
@@ -711,7 +710,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
...
@@ -711,7 +710,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
isRunnable
=
true
isRunnable
=
true
routerInfo
.
handler
.
ServeHTTP
(
rw
,
r
)
routerInfo
.
handler
.
ServeHTTP
(
rw
,
r
)
}
else
{
}
else
{
run
r
outer
=
routerInfo
.
controllerType
run
R
outer
=
routerInfo
.
controllerType
method
:=
r
.
Method
method
:=
r
.
Method
if
r
.
Method
==
"POST"
&&
context
.
Input
.
Query
(
"_method"
)
==
"PUT"
{
if
r
.
Method
==
"POST"
&&
context
.
Input
.
Query
(
"_method"
)
==
"PUT"
{
method
=
"PUT"
method
=
"PUT"
...
@@ -729,17 +728,17 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
...
@@ -729,17 +728,17 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
}
}
}
}
// also defined run
r
outer & runMethod from filter
// also defined run
R
outer & runMethod from filter
if
!
isRunnable
{
if
!
isRunnable
{
//Invoke the request handler
//Invoke the request handler
vc
:=
reflect
.
New
(
run
r
outer
)
vc
:=
reflect
.
New
(
run
R
outer
)
execController
,
ok
:=
vc
.
Interface
()
.
(
ControllerInterface
)
execController
,
ok
:=
vc
.
Interface
()
.
(
ControllerInterface
)
if
!
ok
{
if
!
ok
{
panic
(
"controller is not ControllerInterface"
)
panic
(
"controller is not ControllerInterface"
)
}
}
//call the controller init function
//call the controller init function
execController
.
Init
(
context
,
run
r
outer
.
Name
(),
runMethod
,
vc
.
Interface
())
execController
.
Init
(
context
,
run
R
outer
.
Name
(),
runMethod
,
vc
.
Interface
())
//call prepare function
//call prepare function
execController
.
Prepare
()
execController
.
Prepare
()
...
@@ -790,7 +789,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
...
@@ -790,7 +789,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
}
}
}
}
// finish all run
r
outer. release resource
// finish all run
R
outer. release resource
execController
.
Finish
()
execController
.
Finish
()
}
}
...
@@ -803,31 +802,31 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
...
@@ -803,31 +802,31 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
p
.
execFilter
(
context
,
FinishRouter
,
urlPath
)
p
.
execFilter
(
context
,
FinishRouter
,
urlPath
)
Admin
:
Admin
:
time
end
:=
time
.
Since
(
startt
ime
)
time
Dur
:=
time
.
Since
(
startT
ime
)
//admin module record QPS
//admin module record QPS
if
BConfig
.
Listen
.
AdminEnable
{
if
BConfig
.
Listen
.
AdminEnable
{
if
FilterMonitorFunc
(
r
.
Method
,
r
.
URL
.
Path
,
time
end
)
{
if
FilterMonitorFunc
(
r
.
Method
,
r
.
URL
.
Path
,
time
Dur
)
{
if
run
r
outer
!=
nil
{
if
run
R
outer
!=
nil
{
go
toolbox
.
StatisticsMap
.
AddStatistics
(
r
.
Method
,
r
.
URL
.
Path
,
run
router
.
Name
(),
timeend
)
go
toolbox
.
StatisticsMap
.
AddStatistics
(
r
.
Method
,
r
.
URL
.
Path
,
run
Router
.
Name
(),
timeDur
)
}
else
{
}
else
{
go
toolbox
.
StatisticsMap
.
AddStatistics
(
r
.
Method
,
r
.
URL
.
Path
,
""
,
time
end
)
go
toolbox
.
StatisticsMap
.
AddStatistics
(
r
.
Method
,
r
.
URL
.
Path
,
""
,
time
Dur
)
}
}
}
}
}
}
if
BConfig
.
RunMode
==
DEV
||
BConfig
.
Log
.
AccessLogs
{
if
BConfig
.
RunMode
==
DEV
||
BConfig
.
Log
.
AccessLogs
{
var
dev
i
nfo
string
var
dev
I
nfo
string
if
find
r
outer
{
if
find
R
outer
{
if
routerInfo
!=
nil
{
if
routerInfo
!=
nil
{
dev
info
=
fmt
.
Sprintf
(
"| % -10s | % -40s | % -16s | % -10s | % -40s |"
,
r
.
Method
,
r
.
URL
.
Path
,
timeend
.
String
(),
"match"
,
routerInfo
.
pattern
)
dev
Info
=
fmt
.
Sprintf
(
"| % -10s | % -40s | % -16s | % -10s | % -40s |"
,
r
.
Method
,
r
.
URL
.
Path
,
timeDur
.
String
(),
"match"
,
routerInfo
.
pattern
)
}
else
{
}
else
{
dev
info
=
fmt
.
Sprintf
(
"| % -10s | % -40s | % -16s | % -10s |"
,
r
.
Method
,
r
.
URL
.
Path
,
timeend
.
String
(),
"match"
)
dev
Info
=
fmt
.
Sprintf
(
"| % -10s | % -40s | % -16s | % -10s |"
,
r
.
Method
,
r
.
URL
.
Path
,
timeDur
.
String
(),
"match"
)
}
}
}
else
{
}
else
{
dev
info
=
fmt
.
Sprintf
(
"| % -10s | % -40s | % -16s | % -10s |"
,
r
.
Method
,
r
.
URL
.
Path
,
timeend
.
String
(),
"notmatch"
)
dev
Info
=
fmt
.
Sprintf
(
"| % -10s | % -40s | % -16s | % -10s |"
,
r
.
Method
,
r
.
URL
.
Path
,
timeDur
.
String
(),
"notmatch"
)
}
}
if
DefaultAccessLogFilter
==
nil
||
!
DefaultAccessLogFilter
.
Filter
(
context
)
{
if
DefaultAccessLogFilter
==
nil
||
!
DefaultAccessLogFilter
.
Filter
(
context
)
{
Debug
(
dev
i
nfo
)
Debug
(
dev
I
nfo
)
}
}
}
}
...
@@ -869,7 +868,7 @@ func (p *ControllerRegister) recoverPanic(context *beecontext.Context) {
...
@@ -869,7 +868,7 @@ func (p *ControllerRegister) recoverPanic(context *beecontext.Context) {
}
}
}
}
func
to
u
rl
(
params
map
[
string
]
string
)
string
{
func
to
U
rl
(
params
map
[
string
]
string
)
string
{
if
len
(
params
)
==
0
{
if
len
(
params
)
==
0
{
return
""
return
""
}
}
...
...
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