...
1
2
3
4
5 package render
6
7 import (
8 "net/http"
9
10 "google.golang.org/protobuf/proto"
11 )
12
13
14 type ProtoBuf struct {
15 Data any
16 }
17
18 var protobufContentType = []string{"application/x-protobuf"}
19
20
21 func (r ProtoBuf) Render(w http.ResponseWriter) error {
22 r.WriteContentType(w)
23
24 bytes, err := proto.Marshal(r.Data.(proto.Message))
25 if err != nil {
26 return err
27 }
28
29 _, err = w.Write(bytes)
30 return err
31 }
32
33
34 func (r ProtoBuf) WriteContentType(w http.ResponseWriter) {
35 writeContentType(w, protobufContentType)
36 }
37
View as plain text