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
5588bfc3
Commit
5588bfc3
authored
Mar 29, 2014
by
asta.xie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support filter to get router. get runController & runMethod
parent
2f4acf46
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
26 deletions
+37
-26
input.go
context/input.go
+8
-5
router.go
router.go
+29
-21
No files found.
context/input.go
View file @
5588bfc3
...
...
@@ -4,6 +4,7 @@ import (
"bytes"
"io/ioutil"
"net/http"
"reflect"
"strconv"
"strings"
...
...
@@ -13,11 +14,13 @@ import (
// BeegoInput operates the http request header ,data ,cookie and body.
// it also contains router params and current session.
type
BeegoInput
struct
{
CruSession
session
.
SessionStore
Params
map
[
string
]
string
Data
map
[
interface
{}]
interface
{}
// store some values in this context when calling context in filter or controller.
Request
*
http
.
Request
RequestBody
[]
byte
CruSession
session
.
SessionStore
Params
map
[
string
]
string
Data
map
[
interface
{}]
interface
{}
// store some values in this context when calling context in filter or controller.
Request
*
http
.
Request
RequestBody
[]
byte
RunController
reflect
.
Type
RunMethod
string
}
// NewInput return BeegoInput generated by http.Request.
...
...
router.go
View file @
5588bfc3
...
...
@@ -626,29 +626,37 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
context
.
Input
.
Body
()
}
if
context
.
Input
.
RunController
!=
nil
&&
context
.
Input
.
RunMethod
{
findrouter
=
true
runMethod
=
context
.
Input
.
RunMethod
runrouter
=
context
.
Input
.
RunController
}
//first find path from the fixrouters to Improve Performance
for
_
,
route
:=
range
p
.
fixrouters
{
n
:=
len
(
requestPath
)
if
requestPath
==
route
.
pattern
{
runMethod
=
p
.
getRunMethod
(
r
.
Method
,
context
,
route
)
if
runMethod
!=
""
{
runrouter
=
route
.
controllerType
findrouter
=
true
break
if
!
findrouter
{
for
_
,
route
:=
range
p
.
fixrouters
{
n
:=
len
(
requestPath
)
if
requestPath
==
route
.
pattern
{
runMethod
=
p
.
getRunMethod
(
r
.
Method
,
context
,
route
)
if
runMethod
!=
""
{
runrouter
=
route
.
controllerType
findrouter
=
true
break
}
}
}
// pattern /admin url /admin 200
/admin/ 200
// pattern /admin/ url /admin 301 /admin/ 200
if
requestPath
[
n
-
1
]
!=
'/'
&&
requestPath
+
"/"
==
route
.
pattern
{
http
.
Redirect
(
w
,
r
,
requestPath
+
"/"
,
301
)
goto
Admin
}
if
requestPath
[
n
-
1
]
==
'/'
&&
route
.
pattern
+
"/"
==
requestPath
{
runMethod
=
p
.
getRunMethod
(
r
.
Method
,
context
,
route
)
if
runMethod
!=
""
{
runrouter
=
route
.
controllerTyp
e
findrouter
=
true
break
// pattern /admin url /admin 200 /admin/ 200
// pattern /admin/ url /admin 301
/admin/ 200
if
requestPath
[
n
-
1
]
!=
'/'
&&
requestPath
+
"/"
==
route
.
pattern
{
http
.
Redirect
(
w
,
r
,
requestPath
+
"/"
,
301
)
goto
Admin
}
if
requestPath
[
n
-
1
]
==
'/'
&&
route
.
pattern
+
"/"
==
requestPath
{
runMethod
=
p
.
getRunMethod
(
r
.
Method
,
context
,
route
)
if
runMethod
!=
""
{
runrouter
=
route
.
controllerType
findrouter
=
tru
e
break
}
}
}
}
...
...
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