podman
1// Copyright 2018 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
3// license that can be found in the LICENSE file.
4
5package render
6
7import (
8"net/http"
9
10"google.golang.org/protobuf/proto"
11)
12
13// ProtoBuf contains the given interface object.
14type ProtoBuf struct {
15Data any
16}
17
18var protobufContentType = []string{"application/x-protobuf"}
19
20// Render (ProtoBuf) marshals the given interface object and writes data with custom ContentType.
21func (r ProtoBuf) Render(w http.ResponseWriter) error {
22r.WriteContentType(w)
23
24bytes, err := proto.Marshal(r.Data.(proto.Message))
25if err != nil {
26return err
27}
28
29_, err = w.Write(bytes)
30return err
31}
32
33// WriteContentType (ProtoBuf) writes ProtoBuf ContentType.
34func (r ProtoBuf) WriteContentType(w http.ResponseWriter) {
35writeContentType(w, protobufContentType)
36}
37