protoc-gen-go-triple

command module
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

protoc-gen-go-triple

The protoc-gen-go-triple tool generates Go language bindings for Dubbo services based on protobuf definition files.

For users of dubbo-go version 3.2.0 and above, please use protoc-gen-go-triple version 3.0.0 or higher. It is also recommended for other dubbo-go users to use protoc-gen-go-triple version 3.0.0 or higher. To generate stubs compatible with dubbo-go version 3.1.x and below, please set the following option:

protoc --go-triple_out=useOldVersion=true[,other options...]:.

Prerequisites

Before using protoc-gen-go-triple, make sure you have the following prerequisites installed on your system:

  • Go (version 1.17 or higher)
  • Protocol Buffers (version 3.0 or higher)

Installation

To install protoc-gen-go-triple, you can use the go get command:

go get github.com/dubbogo/protoc-gen-go-triple

Alternatively, you can clone the GitHub repository and build the binary manually:

git clone https://github.com/dubbogo/protoc-gen-go-triple.git
cd protoc-gen-go-triple
go build

Make sure to add the resulting binary to your system's PATH.

Usage

To generate Triple code from your Protocol Buffer files, use the protoc compiler with the protoc-gen-go-triple plugin. Here's an example command:

protoc --go_out=. --go_opt=paths=source_relative --go-triple_out=. your_file.proto

Both the --go_out flag and --go-triple_out flag should be set to .. Please set the generated file path in the proto file using the go_package option.

Example

More dubbo examples using this protoc plugin can be found here apache/dubbo-go-samples

Let's say you have a Protocol Buffer file named greet.proto, and you want to generate Triple Go code from it.

syntax = "proto3";

package greet;


option go_package = "github.com/apache/dubbo-go-samples/helloworld/proto;greet";

message GreetRequest {
  string name = 1;
}

message GreetResponse {
  string greeting = 1;
}

service GreetService {
  rpc Greet(GreetRequest) returns (GreetResponse) {}
}

The package determines the interface path exposed by the Triple service after it is started, which would be:

http://127.0.0.1:20000/greet.GreetService/Greet

The go_package option determines the file generation path and package name

Both parts are indispensable. The directory for the file is determined before ;, and the package to be generated is determined after ;.

Resulting in the following directory structure:

github.com/apache/dubbo-go-samples/helloworld
|-proto
    greet.pb.go
    greet.triple.go

The package for greet.pb.go and greet.triple.go are greet

You can use the following command to generate the Go code:

protoc --go_out=. --go_opt=paths=source_relative --go-triple_out=. greet.proto

This will generate the Go code for the Protobuf code in greet.pb.go and the Triple code in greet.triple.go.

Documentation

Overview

protoc-gen-go-triple is a plugin for the Google protocol buffer compiler to generate Go code.

Check readme for how to use it.

Directories

Path Synopsis
gen
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL