Documentation
¶
Overview ¶
protoc-gen-connect-go is a plugin for the Protobuf compiler that generates Go code. To use it, build this program and make it available on your PATH as protoc-gen-connect-go.
The 'connect-go' suffix becomes part of the arguments for the Protobuf compiler. To generate the base Go types and Connect code using protoc:
protoc --go_out=gen --connect-go_out=gen path/to/file.proto
With buf, your buf.gen.yaml will look like this:
version: v2
plugins:
- local: protoc-gen-go
out: gen
- local: protoc-gen-connect-go
out: gen
This generates service definitions for the Protobuf types and services defined by file.proto. If file.proto defines the foov1 Protobuf package, the invocations above will write output to:
gen/path/to/file.pb.go gen/path/to/foov1connect/file.connect.go
The generated code is configurable with the same parameters as the protoc-gen-go plugin, with the following additional parameters:
- package_suffix: To generate into a sub-package of the package containing the base .pb.go files using the given suffix. An empty suffix denotes to generate into the same package as the base pb.go files. Default is "connect".
For example, to generate into the same package as the base .pb.go files:
version: v2
plugins:
- local: protoc-gen-go
out: gen
- local: protoc-gen-connect-go
out: gen
opt: package_suffix
This will generate output to:
gen/path/to/file.pb.go gen/path/to/file.connect.go