Skip to content

Commit

Permalink
Export the EncodeAsProtobuf on typhon.Response for easier testing
Browse files Browse the repository at this point in the history
  • Loading branch information
suhailpatel authored and intUnderflow committed Jan 18, 2022
1 parent ba9455d commit 61b7194
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions response.go
Expand Up @@ -48,7 +48,7 @@ func (r *Response) Encode(v interface{}) {
// then prefer to encode it as a protobuf response body
acceptsProtobuf := r.Request != nil && strings.Contains(r.Request.Header.Get("Accept"), "application/protobuf")
if m, ok := v.(proto.Message); ok && acceptsProtobuf {
r.encodeAsProtobuf(m)
r.EncodeAsProtobuf(m)
return
}

Expand All @@ -59,7 +59,8 @@ func (r *Response) Encode(v interface{}) {
r.Header.Set("Content-Type", "application/json")
}

func (r *Response) encodeAsProtobuf(m proto.Message) {
// EncodeAsProtobuf serialises the passed object as protobuf into the body
func (r *Response) EncodeAsProtobuf(m proto.Message) {
b, err := proto.Marshal(m)
if err != nil {
r.Error = terrors.Wrap(err, nil)
Expand Down

0 comments on commit 61b7194

Please sign in to comment.