1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-23 13:52:26 +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,17 +157,13 @@ 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 {
switch v := body.(type) {
case []byte: case []byte:
bodyByte = v req.Body = ioutil.NopCloser(bytes.NewReader(b))
default: default:
return errors.New("body type should be []byte") return errors.New("body type should be []byte")
} }
} }
req.Body = ioutil.NopCloser(bytes.NewReader(bodyByte))
}
return nil return nil
} }