From 573c1f50e2898db941b04bbdc34bdc870c582d14 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 21 Mar 2021 17:44:48 +0300 Subject: [PATCH] rewrite query param and not marshal empty struct Signed-off-by: Vasiliy Tolstov --- go.mod | 2 +- go.sum | 4 ++-- http.go | 14 +++++++++++--- util.go | 4 ++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 93d87ac..fd57c07 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/unistack-org/micro-client-http/v3 go 1.16 -require github.com/unistack-org/micro/v3 v3.2.23 +require github.com/unistack-org/micro/v3 v3.2.24 diff --git a/go.sum b/go.sum index 3d96d7b..0af6fae 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,8 @@ github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= github.com/silas/dag v0.0.0-20210121180416-41cf55125c34/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I= -github.com/unistack-org/micro/v3 v3.2.23 h1:kObNEKxVEioUV29nFRg4Mw4KjIXtzggc67yMF1gbXKU= -github.com/unistack-org/micro/v3 v3.2.23/go.mod h1:iJwCWq2PECMxigfqe6TPC5GLWvj6P94Kk+PTVZGL3w8= +github.com/unistack-org/micro/v3 v3.2.24 h1:3sQ72wy8Vap9KDD7bdLOn+dhlPT0iXSJRXhs2qHoKxA= +github.com/unistack-org/micro/v3 v3.2.24/go.mod h1:iJwCWq2PECMxigfqe6TPC5GLWvj6P94Kk+PTVZGL3w8= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/http.go b/http.go index 0a80767..d5084f6 100644 --- a/http.go +++ b/http.go @@ -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)) diff --git a/util.go b/util.go index 2d00dd1..9c6564a 100644 --- a/util.go +++ b/util.go @@ -92,6 +92,10 @@ func newPathRequest(path string, method string, body string, msg interface{}) (s idx++ } + if rutil.IsZero(nmsg) { + return b.String(), nil, nil + } + return b.String(), nmsg, nil }