remove jsonpb
This commit is contained in:
parent
58e0952a9c
commit
1a7c7e97be
26
cure.go
26
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),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user