Skip to content

Commit a73a95a

Browse files
committed
add OptionXXX methods, change SetBodyXml to SetBodyXML
1 parent d6bf256 commit a73a95a

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

request.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ func (req *Request) SetBodyJson(params interface{}) *Request {
307307
return req
308308
}
309309

310-
func (req *Request) SetBodyXml(params interface{}) *Request {
310+
// SetBodyXML set POST body (RAW) to request
311+
func (req *Request) SetBodyXML(params interface{}) *Request {
311312
buff, err := xml.Marshal(params)
312313
if err != nil {
313314
panic(err)
@@ -317,6 +318,7 @@ func (req *Request) SetBodyXml(params interface{}) *Request {
317318
return req
318319
}
319320

321+
// SetBodyXWwwFormUrlencoded set request body x-www-form-urlencoded
320322
func (req *Request) SetBodyXWwwFormUrlencoded(params interface{}) *Request {
321323
req.SetHeaderSingle("Content-Type", "application/x-www-form-urlencoded")
322324
return req.SetBody(params)

request_options.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,38 @@ func OptionBody(v interface{}) OptionFunc {
6060
}
6161
}
6262

63-
// OptionBasicAuth HTTP Basic Authentication
64-
func OptionBasicAuth(username, password string) OptionFunc {
63+
// OptionBodyFormData request body for post (FormData)
64+
func OptionBodyFormData(v interface{}) OptionFunc {
6565
return func(req *Request) {
66-
req.SetBasicAuth(username, password)
66+
req.SetBodyFormData(v)
6767
}
6868
}
6969

70-
// OptionBodyFormData request body for post (FormData)
71-
func OptionBodyFormData(v interface{}) OptionFunc {
70+
// OptionBodyXWwwFormUrlencoded set request body x-www-form-urlencoded
71+
func OptionBodyXWwwFormUrlencoded(v interface{}) OptionFunc {
7272
return func(req *Request) {
73-
req.SetBodyFormData(v)
73+
req.SetBodyXWwwFormUrlencoded(v)
74+
}
75+
}
76+
77+
// OptionBodyJSON request body for post
78+
func OptionBodyJSON(v interface{}) OptionFunc {
79+
return func(req *Request) {
80+
req.SetBodyJson(v)
81+
}
82+
}
83+
84+
// OptionBodyXML request body for post
85+
func OptionBodyXML(v interface{}) OptionFunc {
86+
return func(req *Request) {
87+
req.SetBodyXML(v)
88+
}
89+
}
90+
91+
// OptionBasicAuth HTTP Basic Authentication
92+
func OptionBasicAuth(username, password string) OptionFunc {
93+
return func(req *Request) {
94+
req.SetBasicAuth(username, password)
7495
}
7596
}
7697

0 commit comments

Comments
 (0)