Protocol Buffers Data Type Go Code Generation: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 28: Line 28:
     ./proto/person.proto
     ./proto/person.proto
</syntaxhighlight>
</syntaxhighlight>
The compiler creates a single source file for each <code>.proto</code> file input that is provided on the command line. The name of the output file is the name of the corresponding <code>.proto</code> file where the <code>.proto</code> extension is replaced with <code>.pb.go</code>.
=Arguments=
==<tt>--go_out</tt>==
The directory where you want the compiler to write the Go output.

Revision as of 16:07, 7 May 2024

External

https://protobuf.dev/reference/go/go-generated

Internal

Overview

The Go code that supports the data types defined in the .proto files is generated withe the compiler is invoked with the go_out flag, as shown below, and the Go plugin is installed.

Installation

The generic compiler must be installed with TODO.

To generate Go code, the Go plugin must be installed with:

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

This will install a protoc-gen-go binary in ${GOBIN}.

Code Generation

  protoc \
    --go_out=./pkg/person \
    --proto_path=./proto \
    --go_opt=Mperson.proto=. \
    ./proto/person.proto

The compiler creates a single source file for each .proto file input that is provided on the command line. The name of the output file is the name of the corresponding .proto file where the .proto extension is replaced with .pb.go.

Arguments

--go_out

The directory where you want the compiler to write the Go output.