diff --git a/cure.go b/cure.go index 4f7ddcb..34b3137 100644 --- a/cure.go +++ b/cure.go @@ -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. package cure // import "udico.de/uditaren/cure" import ( "bytes" "context" - "github.com/golang/protobuf/jsonpb" - "github.com/golang/protobuf/proto" + "encoding/json" "github.com/pkg/errors" "github.com/sirupsen/logrus" "io/ioutil" @@ -113,7 +112,7 @@ func (a *Endpoint) PostBody(endpoint string) *call { } func (c *call) Param(param interface{}) *call { - marshaller := new(jsonpb.Marshaler) + /*marshaller := new(jsonpb.Marshaler) marshaller.EmitDefaults = false marshaller.EnumsAsInts = false marshaller.OrigName = true @@ -123,6 +122,13 @@ func (c *call) Param(param interface{}) *call { logrus.Debug(string(buf.Bytes()[:])) c.Body = bytes.NewReader(buf.Bytes()) 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 { @@ -165,12 +171,12 @@ func (c *call) Fire(ctx context.Context, result interface{}) callret { 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 { - logrus.Debugf(" [%v: %v]", k, v) + logrus.Tracef(" [%v: %v]", k, v) } for k, v := range c.Parameters { - logrus.Debugf(" + %v = '%v'", k, v) + logrus.Tracef(" + %v = '%v'", k, v) } hbuf := &bytes.Buffer{} @@ -198,11 +204,11 @@ func (c *call) Fire(ctx context.Context, result interface{}) callret { bbuf := bytes.NewReader(buf) logrus.Debug(string(buf[:])) - unmarshaller := new(jsonpb.Unmarshaler) - unmarshaller.AllowUnknownFields = true + unmarshaller := json.NewDecoder(bbuf) //new(jsonpb.Unmarshaler) + //unmarshaller.AllowUnknownFields = true return callret{ response.StatusCode, response.Status, - unmarshaller.Unmarshal(bbuf, result.(proto.Message)), + unmarshaller.Decode(result), } }