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
862ea226
Commit
862ea226
authored
Aug 23, 2015
by
Shuai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化设置参数
parent
ff92f22d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
19 deletions
+10
-19
httplib.go
httplib/httplib.go
+10
-19
No files found.
httplib/httplib.go
View file @
862ea226
...
...
@@ -100,7 +100,7 @@ func NewBeegoRequest(rawurl, method string) *BeegoHttpRequest {
return
&
BeegoHttpRequest
{
url
:
rawurl
,
req
:
&
req
,
params
:
map
[
string
]
interface
{}
{},
params
:
map
[
string
][]
string
{},
files
:
map
[
string
]
string
{},
setting
:
defaultSetting
,
resp
:
&
resp
,
...
...
@@ -150,7 +150,7 @@ type BeegoHttpSettings struct {
type
BeegoHttpRequest
struct
{
url
string
req
*
http
.
Request
params
map
[
string
]
interface
{}
params
map
[
string
][]
string
files
map
[
string
]
string
setting
BeegoHttpSettings
resp
*
http
.
Response
...
...
@@ -272,8 +272,12 @@ func (b *BeegoHttpRequest) SetProxy(proxy func(*http.Request) (*url.URL, error))
// Param adds query param in to request.
// params build query string as ?key1=value1&key2=value2...
func
(
b
*
BeegoHttpRequest
)
Param
(
key
string
,
value
interface
{})
*
BeegoHttpRequest
{
b
.
params
[
key
]
=
value
func
(
b
*
BeegoHttpRequest
)
Param
(
key
,
value
string
)
*
BeegoHttpRequest
{
if
param
,
ok
:=
b
.
params
[
key
];
ok
{
b
.
params
[
key
]
=
append
(
param
,
value
)
}
else
{
b
.
params
[
key
]
=
[]
string
{
value
}
}
return
b
}
...
...
@@ -348,15 +352,10 @@ func (b *BeegoHttpRequest) buildUrl(paramBody string) {
}
}
for
k
,
v
:=
range
b
.
params
{
switch
v
.
(
type
)
{
case
string
:
bodyWriter
.
WriteField
(
k
,
v
.
(
string
))
case
[]
string
:
for
_
,
vv
:=
range
v
.
([]
string
)
{
for
_
,
vv
:=
range
v
{
bodyWriter
.
WriteField
(
k
,
vv
)
}
}
}
bodyWriter
.
Close
()
pw
.
Close
()
}()
...
...
@@ -390,21 +389,13 @@ func (b *BeegoHttpRequest) SendOut() (*http.Response, error) {
if
len
(
b
.
params
)
>
0
{
var
buf
bytes
.
Buffer
for
k
,
v
:=
range
b
.
params
{
switch
v
.
(
type
)
{
case
string
:
buf
.
WriteString
(
url
.
QueryEscape
(
k
))
buf
.
WriteByte
(
'='
)
buf
.
WriteString
(
url
.
QueryEscape
(
v
.
(
string
)))
buf
.
WriteByte
(
'&'
)
case
[]
string
:
for
_
,
vv
:=
range
v
.
([]
string
)
{
for
_
,
vv
:=
range
v
{
buf
.
WriteString
(
url
.
QueryEscape
(
k
))
buf
.
WriteByte
(
'='
)
buf
.
WriteString
(
url
.
QueryEscape
(
vv
))
buf
.
WriteByte
(
'&'
)
}
}
}
paramBody
=
buf
.
String
()
paramBody
=
paramBody
[
0
:
len
(
paramBody
)
-
1
]
}
...
...
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