Skip to content

Latest commit

 

History

History
98 lines (66 loc) · 2.19 KB

File metadata and controls

98 lines (66 loc) · 2.19 KB

protoc-gen-go-triple

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.

Requirements

  • Go 1.23 or later
  • protoc
  • protoc-gen-go

Install protoc-gen-go if it is not already available:

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

Installation

go install dubbo.apache.org/dubbo-go/v3/tools/protoc-gen-go-triple@latest

Make sure $(go env GOPATH)/bin is in your PATH.

Usage

protoc \
  --go_out=. \
  --go_opt=paths=source_relative \
  --go-triple_out=. \
  --go-triple_opt=paths=source_relative \
  ./api/greet.proto

For greet.proto, the generated files are:

  • greet.pb.go: protobuf messages generated by protoc-gen-go
  • greet.triple.go: Triple bindings generated by protoc-gen-go-triple

Proto Example

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.

Generated API

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.

Legacy Compatibility

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.proto

The old compatibility mode is retained for migration only. New projects should use the default output.