Home / File/ protobuf.go — gin Source File

protobuf.go — gin Source File

Architecture documentation for protobuf.go, a go file in the gin codebase. 1 imports, 0 dependents.

File go 1 imports 1 classes

Entity Profile

Dependency Diagram

graph LR
  d15ac5f9_c425_a6dd_178e_04188f81573e["protobuf.go"]
  08248871_dc00_f330_15ef_4a0fbf2bafbb["http"]
  d15ac5f9_c425_a6dd_178e_04188f81573e --> 08248871_dc00_f330_15ef_4a0fbf2bafbb
  style d15ac5f9_c425_a6dd_178e_04188f81573e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// Copyright 2018 Gin Core Team. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package render

import (
	"net/http"

	"google.golang.org/protobuf/proto"
)

// ProtoBuf contains the given interface object.
type ProtoBuf struct {
	Data any
}

var protobufContentType = []string{"application/x-protobuf"}

// Render (ProtoBuf) marshals the given interface object and writes data with custom ContentType.
func (r ProtoBuf) Render(w http.ResponseWriter) error {
	r.WriteContentType(w)

	bytes, err := proto.Marshal(r.Data.(proto.Message))
	if err != nil {
		return err
	}

	_, err = w.Write(bytes)
	return err
}

// WriteContentType (ProtoBuf) writes ProtoBuf ContentType.
func (r ProtoBuf) WriteContentType(w http.ResponseWriter) {
	writeContentType(w, protobufContentType)
}

Types

Dependencies

  • http

Frequently Asked Questions

What does protobuf.go do?
protobuf.go is a source file in the gin codebase, written in go.
What does protobuf.go depend on?
protobuf.go imports 1 module(s): http.
Where is protobuf.go in the architecture?
protobuf.go is located at render/protobuf.go (directory: render).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free