正在生成服务,但没有客户端协议。

huangapple go评论69阅读模式
英文:

Service being generated but not client protoc

问题

我正在使用protoc尝试为我的gRPC服务生成客户端/服务器。

我在我的make文件中有以下内容:

stripe:
	@protoc --go_out=. pkg/proto/stripe/service.proto

我的proto文件是

syntax = "proto3";
package grpc;
option go_package = "pkg/proto/stripe/";

service Stripe {
  rpc UpdateVerification(UpdateVerificationRequest) returns (UpdateVerificationResponse);
}

message UpdateVerificationRequest {
  string id = 1;
}

message UpdateVerificationResponse {
}

当我运行make stripe时,它会生成一个service.pb.go文件,但没有生成接口或客户端。

这是我在生成CLI命令中遗漏的东西吗?

英文:

I am using protoc to try and generate a client / server for my gRPC service.

I have the following in my make file

stripe:
	@protoc --go_out=. pkg/proto/stripe/service.proto

My proto file is

syntax = "proto3";
package grpc;
option go_package = "pkg/proto/stripe/";

service Stripe {
  rpc UpdateVerification(UpdateVerificationRequest) returns (UpdateVerificationResponse);
}

message UpdateVerificationRequest {
  string id = 1;
}

message UpdateVerificationResponse {
}

When I run make stripe it generates a service.pb.go but there is no interface or client generated.

Is this something I am missing in the generation CLI command?

答案1

得分: 1

尝试添加go-grpc_out,例如:

protoc --go_out=. --go-grpc_out=. pkg/proto/stripe/service.proto

这将在与proto文件相同的目录中生成service_grpc.pb.go文件。

根据快速入门指南的建议,完整的命令可以是:

protoc --go_out=. --go_opt=paths=source_relative \
    --go-grpc_out=. --go-grpc_opt=paths=source_relative \
    pkg/proto/stripe/service.proto
英文:

Try adding go-grpc_out, as example:

protoc --go_out=. --go-grpc_out=.   pkg/proto/stripe/service.proto

Will generate also the service_grpc.pb.go file in the same dir of the proto

As suggested in the quickstart giude, the full command could be:

protoc --go_out=. --go_opt=paths=source_relative \
    --go-grpc_out=. --go-grpc_opt=paths=source_relative \
    pkg/proto/stripe/service.proto

huangapple
  • 本文由 发表于 2021年12月18日 22:03:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/70404055.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定