...

Source file src/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/marshal_httpbodyproto.go

Documentation: github.com/grpc-ecosystem/grpc-gateway/v2/runtime

     1  package runtime
     2  
     3  import (
     4  	"google.golang.org/genproto/googleapis/api/httpbody"
     5  )
     6  
     7  // HTTPBodyMarshaler is a Marshaler which supports marshaling of a
     8  // google.api.HttpBody message as the full response body if it is
     9  // the actual message used as the response. If not, then this will
    10  // simply fallback to the Marshaler specified as its default Marshaler.
    11  type HTTPBodyMarshaler struct {
    12  	Marshaler
    13  }
    14  
    15  // ContentType returns its specified content type in case v is a
    16  // google.api.HttpBody message, otherwise it will fall back to the default Marshalers
    17  // content type.
    18  func (h *HTTPBodyMarshaler) ContentType(v interface{}) string {
    19  	if httpBody, ok := v.(*httpbody.HttpBody); ok {
    20  		return httpBody.GetContentType()
    21  	}
    22  	return h.Marshaler.ContentType(v)
    23  }
    24  
    25  // Marshal marshals "v" by returning the body bytes if v is a
    26  // google.api.HttpBody message, otherwise it falls back to the default Marshaler.
    27  func (h *HTTPBodyMarshaler) Marshal(v interface{}) ([]byte, error) {
    28  	if httpBody, ok := v.(*httpbody.HttpBody); ok {
    29  		return httpBody.GetData(), nil
    30  	}
    31  	return h.Marshaler.Marshal(v)
    32  }
    33  

View as plain text