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
03080b3e
Commit
03080b3e
authored
May 20, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
beego:1.2.0
parent
b45f0b9b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
30 deletions
+26
-30
router.go
router.go
+0
-5
router_test.go
router_test.go
+17
-22
file.go
utils/file.go
+9
-3
No files found.
router.go
View file @
03080b3e
...
@@ -797,14 +797,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
...
@@ -797,14 +797,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
}
}
if
len
(
route
.
params
)
>
0
{
if
len
(
route
.
params
)
>
0
{
//add url parameters to the query param map
values
:=
r
.
URL
.
Query
()
for
i
,
match
:=
range
matches
[
1
:
]
{
for
i
,
match
:=
range
matches
[
1
:
]
{
values
.
Add
(
route
.
params
[
i
],
match
)
params
[
route
.
params
[
i
]]
=
match
params
[
route
.
params
[
i
]]
=
match
}
}
//reassemble query params and add to RawQuery
r
.
URL
.
RawQuery
=
url
.
Values
(
values
)
.
Encode
()
}
}
runMethod
=
p
.
getRunMethod
(
r
.
Method
,
context
,
route
)
runMethod
=
p
.
getRunMethod
(
r
.
Method
,
context
,
route
)
if
runMethod
!=
""
{
if
runMethod
!=
""
{
...
...
router_test.go
View file @
03080b3e
...
@@ -43,6 +43,15 @@ func (this *TestController) GetUrl() {
...
@@ -43,6 +43,15 @@ func (this *TestController) GetUrl() {
this
.
Ctx
.
Output
.
Body
([]
byte
(
this
.
UrlFor
(
".Myext"
)))
this
.
Ctx
.
Output
.
Body
([]
byte
(
this
.
UrlFor
(
".Myext"
)))
}
}
func
(
t
*
TestController
)
GetParams
()
{
t
.
Ctx
.
WriteString
(
t
.
Ctx
.
Input
.
Query
(
":last"
)
+
"+"
+
t
.
Ctx
.
Input
.
Query
(
":first"
)
+
"+"
+
t
.
Ctx
.
Input
.
Query
(
"learn"
))
}
func
(
t
*
TestController
)
GetManyRouter
()
{
t
.
Ctx
.
WriteString
(
t
.
Ctx
.
Input
.
Query
(
":id"
)
+
t
.
Ctx
.
Input
.
Query
(
":page"
))
}
type
ResStatus
struct
{
type
ResStatus
struct
{
Code
int
Code
int
Msg
string
Msg
string
...
@@ -147,21 +156,11 @@ func TestRouteOk(t *testing.T) {
...
@@ -147,21 +156,11 @@ func TestRouteOk(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegistor
()
handler
:=
NewControllerRegistor
()
handler
.
Add
(
"/person/:last/:first"
,
&
TestController
{})
handler
.
Add
(
"/person/:last/:first"
,
&
TestController
{}
,
"get:GetParams"
)
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
body
:=
w
.
Body
.
String
()
lastNameParam
:=
r
.
URL
.
Query
()
.
Get
(
":last"
)
if
body
!=
"anderson+thomas+kungfu"
{
firstNameParam
:=
r
.
URL
.
Query
()
.
Get
(
":first"
)
t
.
Errorf
(
"url param set to [%s];"
,
body
)
learnParam
:=
r
.
URL
.
Query
()
.
Get
(
"learn"
)
if
lastNameParam
!=
"anderson"
{
t
.
Errorf
(
"url param set to [%s]; want [%s]"
,
lastNameParam
,
"anderson"
)
}
if
firstNameParam
!=
"thomas"
{
t
.
Errorf
(
"url param set to [%s]; want [%s]"
,
firstNameParam
,
"thomas"
)
}
if
learnParam
!=
"kungfu"
{
t
.
Errorf
(
"url param set to [%s]; want [%s]"
,
learnParam
,
"kungfu"
)
}
}
}
}
...
@@ -171,17 +170,13 @@ func TestManyRoute(t *testing.T) {
...
@@ -171,17 +170,13 @@ func TestManyRoute(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegistor
()
handler
:=
NewControllerRegistor
()
handler
.
Add
(
"/beego:id([0-9]+)-:page([0-9]+).html"
,
&
TestController
{})
handler
.
Add
(
"/beego:id([0-9]+)-:page([0-9]+).html"
,
&
TestController
{}
,
"get:GetManyRouter"
)
handler
.
ServeHTTP
(
w
,
r
)
handler
.
ServeHTTP
(
w
,
r
)
id
:=
r
.
URL
.
Query
()
.
Get
(
":id"
)
body
:=
w
.
Body
.
String
()
page
:=
r
.
URL
.
Query
()
.
Get
(
":page"
)
if
id
!=
"32"
{
if
body
!=
"3212"
{
t
.
Errorf
(
"url param set to [%s]; want [%s]"
,
id
,
"32"
)
t
.
Errorf
(
"url param set to [%s];"
,
body
)
}
if
page
!=
"12"
{
t
.
Errorf
(
"url param set to [%s]; want [%s]"
,
page
,
"12"
)
}
}
}
}
...
...
utils/file.go
View file @
03080b3e
...
@@ -64,24 +64,30 @@ func GrepFile(patten string, filename string) (lines []string, err error) {
...
@@ -64,24 +64,30 @@ func GrepFile(patten string, filename string) (lines []string, err error) {
lines
=
make
([]
string
,
0
)
lines
=
make
([]
string
,
0
)
reader
:=
bufio
.
NewReader
(
fd
)
reader
:=
bufio
.
NewReader
(
fd
)
prefix
:=
""
prefix
:=
""
isLongLine
:=
false
for
{
for
{
byteLine
,
isPrefix
,
er
:=
reader
.
ReadLine
()
byteLine
,
isPrefix
,
er
:=
reader
.
ReadLine
()
if
er
!=
nil
&&
er
!=
io
.
EOF
{
if
er
!=
nil
&&
er
!=
io
.
EOF
{
return
nil
,
er
return
nil
,
er
}
}
if
er
==
io
.
EOF
{
break
}
line
:=
string
(
byteLine
)
line
:=
string
(
byteLine
)
if
isPrefix
{
if
isPrefix
{
prefix
+=
line
prefix
+=
line
continue
continue
}
else
{
isLongLine
=
true
}
}
line
=
prefix
+
line
line
=
prefix
+
line
if
isLongLine
{
prefix
=
""
}
if
re
.
MatchString
(
line
)
{
if
re
.
MatchString
(
line
)
{
lines
=
append
(
lines
,
line
)
lines
=
append
(
lines
,
line
)
}
}
if
er
==
io
.
EOF
{
break
}
}
}
return
lines
,
nil
return
lines
,
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