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
4ce584c5
Commit
4ce584c5
authored
Sep 22, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #201
parent
3c1d23bc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletion
+25
-1
router.go
router.go
+9
-1
router_test.go
router_test.go
+16
-0
No files found.
router.go
View file @
4ce584c5
...
@@ -311,7 +311,6 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
...
@@ -311,7 +311,6 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
params
:=
make
(
map
[
string
]
string
)
params
:=
make
(
map
[
string
]
string
)
context
.
Input
.
Param
=
params
if
p
.
enableFilter
{
if
p
.
enableFilter
{
if
l
,
ok
:=
p
.
filters
[
"BeforRouter"
];
ok
{
if
l
,
ok
:=
p
.
filters
[
"BeforRouter"
];
ok
{
for
_
,
filterR
:=
range
l
{
for
_
,
filterR
:=
range
l
{
...
@@ -412,6 +411,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
...
@@ -412,6 +411,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
break
break
}
}
}
}
context
.
Input
.
Param
=
params
if
runrouter
!=
nil
{
if
runrouter
!=
nil
{
if
r
.
Method
==
"POST"
{
if
r
.
Method
==
"POST"
{
...
@@ -584,6 +584,14 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
...
@@ -584,6 +584,14 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
if
p
.
enableAuto
{
if
p
.
enableAuto
{
if
!
findrouter
{
if
!
findrouter
{
lastindex
:=
strings
.
LastIndex
(
requestPath
,
"/"
)
lastsub
:=
requestPath
[
lastindex
+
1
:
]
if
subindex
:=
strings
.
LastIndex
(
lastsub
,
"."
);
subindex
!=
-
1
{
context
.
Input
.
Param
[
":ext"
]
=
lastsub
[
subindex
+
1
:
]
r
.
URL
.
Query
()
.
Add
(
":ext"
,
lastsub
[
subindex
+
1
:
])
r
.
URL
.
RawQuery
=
r
.
URL
.
Query
()
.
Encode
()
requestPath
=
requestPath
[
:
len
(
requestPath
)
-
len
(
lastsub
[
subindex
:
])]
}
for
cName
,
methodmap
:=
range
p
.
autoRouter
{
for
cName
,
methodmap
:=
range
p
.
autoRouter
{
if
strings
.
ToLower
(
requestPath
)
==
"/"
+
cName
{
if
strings
.
ToLower
(
requestPath
)
==
"/"
+
cName
{
...
...
router_test.go
View file @
4ce584c5
...
@@ -21,6 +21,10 @@ func (this *TestController) List() {
...
@@ -21,6 +21,10 @@ func (this *TestController) List() {
this
.
Ctx
.
Output
.
Body
([]
byte
(
"i am list"
))
this
.
Ctx
.
Output
.
Body
([]
byte
(
"i am list"
))
}
}
func
(
this
*
TestController
)
Myext
()
{
this
.
Ctx
.
Output
.
Body
([]
byte
(
this
.
Ctx
.
Input
.
Params
(
":ext"
)))
}
func
TestUserFunc
(
t
*
testing
.
T
)
{
func
TestUserFunc
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/api/list"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/api/list"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
...
@@ -45,6 +49,18 @@ func TestAutoFunc(t *testing.T) {
...
@@ -45,6 +49,18 @@ func TestAutoFunc(t *testing.T) {
}
}
}
}
func
TestAutoExtFunc
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/test/myext.json"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegistor
()
handler
.
AddAuto
(
&
TestController
{})
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"json"
{
t
.
Errorf
(
"user define func can't run"
)
}
}
func
TestRouteOk
(
t
*
testing
.
T
)
{
func
TestRouteOk
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/person/anderson/thomas?learn=kungfu"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/person/anderson/thomas?learn=kungfu"
,
nil
)
...
...
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