English | 中文
protoc-gen-go-triple is the protobuf compiler plugin that generates dubbo-go Triple client and server bindings.
It works together with protoc-gen-go: protoc-gen-go generates protobuf message types, and protoc-gen-go-triple generates Triple service interfaces, clients, handlers, and registration helpers.
- Go 1.23 or later
protocprotoc-gen-go
Install protoc-gen-go if it is not already available:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latestgo install dubbo.apache.org/dubbo-go/v3/tools/protoc-gen-go-triple@latestMake sure $(go env GOPATH)/bin is in your PATH.
protoc \
--go_out=. \
--go_opt=paths=source_relative \
--go-triple_out=. \
--go-triple_opt=paths=source_relative \
./api/greet.protoFor greet.proto, the generated files are:
greet.pb.go: protobuf messages generated byprotoc-gen-gogreet.triple.go: Triple bindings generated byprotoc-gen-go-triple
syntax = "proto3";
package greet;
option go_package = "example.com/hello/api;api";
message GreetRequest {
string name = 1;
}
message GreetResponse {
string greeting = 1;
}
service GreetService {
rpc Greet(GreetRequest) returns (GreetResponse) {}
}The protobuf package controls the Triple service name exposed on the wire. The go_package option controls the Go import path and package name for generated files.
Current generated code uses the dubbo-go v3 Triple API:
greeter, err := api.NewGreetService(cli)err := api.RegisterGreetServiceHandler(srv, &GreetServiceImpl{})The generated file suffix is .triple.go.
For dubbo-go 3.2.0 and later, use the default generator output.
To generate stubs compatible with older dubbo-go releases, pass useOldVersion=true:
protoc \
--go_out=. \
--go_opt=paths=source_relative \
--go-triple_out=. \
--go-triple_opt=paths=source_relative,useOldVersion=true \
./api/greet.protoThe old compatibility mode is retained for migration only. New projects should use the default output.