rewrite query param and not marshal empty struct

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-03-21 17:44:48 +03:00
parent 602aed03bd
commit 573c1f50e2
4 changed files with 18 additions and 6 deletions

14
http.go
View File

@@ -71,13 +71,21 @@ func newRequest(addr string, req client.Request, cf codec.Codec, msg interface{}
return nil, errors.BadRequest("go.micro.client", err.Error())
}
hreq.URL.Path = path
// marshal request
b, err := cf.Marshal(nmsg)
hreq.URL, err = url.Parse(addr + path)
if err != nil {
return nil, errors.BadRequest("go.micro.client", err.Error())
}
var b []byte
// marshal request is struct not empty
if nmsg != nil {
b, err = cf.Marshal(nmsg)
if err != nil {
return nil, errors.BadRequest("go.micro.client", err.Error())
}
}
hreq.Body = ioutil.NopCloser(bytes.NewBuffer(b))
hreq.ContentLength = int64(len(b))