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
9edf3143
authored
2013-12-18 10:00:52 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix autorouter params
1 parent
00065f2b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
router.go
router_test.go
router.go
View file @
9edf314
...
...
@@ -634,6 +634,14 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
runrouter
=
controllerType
runMethod
=
mName
findrouter
=
true
//parse params
otherurl
:=
requestPath
[
len
(
"/"
+
cName
+
"/"
+
strings
.
ToLower
(
mName
))
:
]
if
len
(
otherurl
)
>
1
{
plist
:=
strings
.
Split
(
otherurl
,
"/"
)
for
k
,
v
:=
range
plist
[
1
:
]
{
context
.
Input
.
Params
[
strconv
.
Itoa
(
k
)]
=
v
}
}
break
}
}
...
...
router_test.go
View file @
9edf314
...
...
@@ -19,6 +19,10 @@ func (this *TestController) List() {
this
.
Ctx
.
Output
.
Body
([]
byte
(
"i am list"
))
}
func
(
this
*
TestController
)
Params
()
{
this
.
Ctx
.
Output
.
Body
([]
byte
(
this
.
Ctx
.
Input
.
Params
[
"0"
]
+
this
.
Ctx
.
Input
.
Params
[
"1"
]
+
this
.
Ctx
.
Input
.
Params
[
"2"
]))
}
func
(
this
*
TestController
)
Myext
()
{
this
.
Ctx
.
Output
.
Body
([]
byte
(
this
.
Ctx
.
Input
.
Param
(
":ext"
)))
}
...
...
@@ -89,6 +93,18 @@ func TestAutoFunc(t *testing.T) {
}
}
func
TestAutoFuncParams
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/test/params/2009/11/12"
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegistor
()
handler
.
AddAuto
(
&
TestController
{})
handler
.
ServeHTTP
(
w
,
r
)
if
w
.
Body
.
String
()
!=
"20091112"
{
t
.
Errorf
(
"user define func can't run"
)
}
}
func
TestAutoExtFunc
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/test/myext.json"
,
nil
)
w
:=
httptest
.
NewRecorder
()
...
...
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