1// Copyright 2018 Gin Core Team. All rights reserved.2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45package render67import (8 "net/http"910 "google.golang.org/protobuf/proto"11)1213// ProtoBuf contains the given interface object.14type ProtoBuf struct {15 Data any16}1718var protobufContentType = []string{"application/x-protobuf"}1920// Render (ProtoBuf) marshals the given interface object and writes data with custom ContentType.21func (r ProtoBuf) Render(w http.ResponseWriter) error {22 r.WriteContentType(w)2324 bytes, err := proto.Marshal(r.Data.(proto.Message))25 if err != nil {26 return err27 }2829 _, err = w.Write(bytes)30 return err31}3233// WriteContentType (ProtoBuf) writes ProtoBuf ContentType.34func (r ProtoBuf) WriteContentType(w http.ResponseWriter) {35 writeContentType(w, protobufContentType)36}