remove jsonpb

This commit is contained in:
Thilo Karraß 2021-10-18 14:58:35 +02:00
parent 58e0952a9c
commit 1a7c7e97be

26
cure.go
View File

@ -1,12 +1,11 @@
// Common Uniform Rest Endpoint // Package cure is the Common Uniform Rest Endpoint
// //
// This is a library to access REST endpoints in a simplified way. // This is a library to access REST endpoints in a simplified way.
package cure // import "udico.de/uditaren/cure" package cure // import "udico.de/uditaren/cure"
import ( import (
"bytes" "bytes"
"context" "context"
"github.com/golang/protobuf/jsonpb" "encoding/json"
"github.com/golang/protobuf/proto"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"io/ioutil" "io/ioutil"
@ -113,7 +112,7 @@ func (a *Endpoint) PostBody(endpoint string) *call {
} }
func (c *call) Param(param interface{}) *call { func (c *call) Param(param interface{}) *call {
marshaller := new(jsonpb.Marshaler) /*marshaller := new(jsonpb.Marshaler)
marshaller.EmitDefaults = false marshaller.EmitDefaults = false
marshaller.EnumsAsInts = false marshaller.EnumsAsInts = false
marshaller.OrigName = true marshaller.OrigName = true
@ -123,6 +122,13 @@ func (c *call) Param(param interface{}) *call {
logrus.Debug(string(buf.Bytes()[:])) logrus.Debug(string(buf.Bytes()[:]))
c.Body = bytes.NewReader(buf.Bytes()) c.Body = bytes.NewReader(buf.Bytes())
return c return c
*/
buf := &bytes.Buffer{}
jEnc := json.NewEncoder(buf)
jEnc.Encode(param)
logrus.Trace(string(buf.Bytes()))
c.Body = bytes.NewReader(buf.Bytes())
return c
} }
func (c *call) Fire(ctx context.Context, result interface{}) callret { func (c *call) Fire(ctx context.Context, result interface{}) callret {
@ -165,12 +171,12 @@ func (c *call) Fire(ctx context.Context, result interface{}) callret {
request.URL.RawQuery = gdata.Encode() request.URL.RawQuery = gdata.Encode()
} }
logrus.Debugf("%v %v", c.method, c.url) logrus.Tracef("%v %v", c.method, c.url)
for k, v := range c.Head { for k, v := range c.Head {
logrus.Debugf(" [%v: %v]", k, v) logrus.Tracef(" [%v: %v]", k, v)
} }
for k, v := range c.Parameters { for k, v := range c.Parameters {
logrus.Debugf(" + %v = '%v'", k, v) logrus.Tracef(" + %v = '%v'", k, v)
} }
hbuf := &bytes.Buffer{} hbuf := &bytes.Buffer{}
@ -198,11 +204,11 @@ func (c *call) Fire(ctx context.Context, result interface{}) callret {
bbuf := bytes.NewReader(buf) bbuf := bytes.NewReader(buf)
logrus.Debug(string(buf[:])) logrus.Debug(string(buf[:]))
unmarshaller := new(jsonpb.Unmarshaler) unmarshaller := json.NewDecoder(bbuf) //new(jsonpb.Unmarshaler)
unmarshaller.AllowUnknownFields = true //unmarshaller.AllowUnknownFields = true
return callret{ return callret{
response.StatusCode, response.StatusCode,
response.Status, response.Status,
unmarshaller.Unmarshal(bbuf, result.(proto.Message)), unmarshaller.Decode(result),
} }
} }