...
1 package runtime
2
3 import (
4 "google.golang.org/genproto/googleapis/api/httpbody"
5 )
6
7
8 func SetHTTPBodyMarshaler(serveMux *ServeMux) {
9 serveMux.marshalers.mimeMap[MIMEWildcard] = &HTTPBodyMarshaler{
10 Marshaler: &JSONPb{OrigName: true},
11 }
12 }
13
14
15
16
17
18 type HTTPBodyMarshaler struct {
19 Marshaler
20 }
21
22
23 func (h *HTTPBodyMarshaler) ContentType() string {
24 return h.ContentTypeFromMessage(nil)
25 }
26
27
28
29 func (h *HTTPBodyMarshaler) ContentTypeFromMessage(v interface{}) string {
30 if httpBody, ok := v.(*httpbody.HttpBody); ok {
31 return httpBody.GetContentType()
32 }
33 return h.Marshaler.ContentType()
34 }
35
36
37
38 func (h *HTTPBodyMarshaler) Marshal(v interface{}) ([]byte, error) {
39 if httpBody, ok := v.(*httpbody.HttpBody); ok {
40 return httpBody.Data, nil
41 }
42 return h.Marshaler.Marshal(v)
43 }
44
View as plain text