pb2tarsgo
用法
install protoc https://github.com/protocolbuffers/protobuf/releases
Install protoc-gen-go and protoc-gen-go-tarsrpc
export PATH=$PATH:$GOPATH/bin
# < go 1.16
go get -u google.golang.org/protobuf/cmd/protoc-gen-go
go get -u github.com/TarsCloud/TarsGo/tars/tools/protoc-gen-go-tarsrpc
# >= go 1.16
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install github.com/TarsCloud/TarsGo/tars/tools/protoc-gen-go-tarsrpc@latest示例
创建项目目录
mkdir pb2tarsgo
cd pb2tarsgo
go mod init pb2tarsgohelloworld.proto 文件
syntax = "proto3";
package helloworld;
option go_package = "pb2tarsgo/helloworld";
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}生成代码
服务端
main.go
客户端
client/client.go
配置文件
config.conf
Last updated
Was this helpful?