mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-13 09:12:28 +08:00
refactor: set body byte for http post request
This commit is contained in:
@@ -157,16 +157,12 @@ func setQueryParam(req *http.Request, reqUrl string, queryParam interface{}) err
|
|||||||
|
|
||||||
func setBodyByte(req *http.Request, body interface{}) error {
|
func setBodyByte(req *http.Request, body interface{}) error {
|
||||||
if body != nil {
|
if body != nil {
|
||||||
var bodyByte []byte
|
switch b := body.(type) {
|
||||||
if body != nil {
|
case []byte:
|
||||||
switch v := body.(type) {
|
req.Body = ioutil.NopCloser(bytes.NewReader(b))
|
||||||
case []byte:
|
default:
|
||||||
bodyByte = v
|
return errors.New("body type should be []byte")
|
||||||
default:
|
|
||||||
return errors.New("body type should be []byte")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
req.Body = ioutil.NopCloser(bytes.NewReader(bodyByte))
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user