1
0
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:
dudaodong
2022-02-25 15:31:39 +08:00
parent 85886cf618
commit f26477904e

View File

@@ -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
} }