运行 protoc 命令时没有生成 Register 方法。

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

Running protoc commands not generating Register method

问题

我正在尝试在grpc go中使用插件方法生成服务。

这是我的score.proto文件:

syntax = "proto3";
option go_package = "./livescore";

service ScoreService {
  rpc ListMatches(ListMatchesRequest) returns (ListMatchesResponse);
}

message ListMatchesRequest {
  string country = 1;
}

message MatchScoreResponse {
  string score = 1;
  bool live = 2;
}

message ListMatchesResponse {
  repeated MatchScoreResponse scores = 1;
}

当我运行以下命令时:

protoc -I=. --go_out=. score.proto

它正常工作。

但是,当我运行以下命令以生成RegisterScoreServiceServer时:

protoc -I=. --go-grpc_out=. score.proto

它给我报错:

protoc-gen-go-grpc: program not found or is not executable

我知道插件标志已被弃用,但是如何同时生成插件还是有点困惑。任何帮助将不胜感激。

英文:

I am trying to generate service with plugin methods in for grpc go

This is my score.proto file

syntax="proto3";
option go_package="./livescore";

service ScoreService{
  rpc ListMatches(ListMatchesRequest) returns (ListMatchesResponse);
}

message ListMatchesRequest{
  string country=1;
}


message MatchScoreResponse{
  string score =1;
  bool live=2;
}
message ListMatchesResponse{
  repeated MatchScoreResponse scores=1;

}

When I am running this command

protoc -I=. --go_out=. score.proto  

its working fine

But following command to generate RegisterScoreServiceServer as well

protoc -I=. --go-grpc_out=. score.proto 

is giving me error

protoc-gen-go-grpc: program not found or is not executable

I know the plugins flag is deprecated ,but then how to generate plugins as well .Its bit confusing any help would be welcome

答案1

得分: 1

如果你仔细查看文档,它提到需要安装两个东西:

$ go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26
$ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1

对于第二个命令,你还需要安装go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1

如果需要更多信息,请查看这里:

https://pkg.go.dev/google.golang.org/grpc/cmd/protoc-gen-go-grpc#section-readme

英文:

If you see the docs closely it mentions two things to be installed

$ go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26
$ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1

For second command you need go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1

to be installed too.

For more look here

https://pkg.go.dev/google.golang.org/grpc/cmd/protoc-gen-go-grpc#section-readme

huangapple
  • 本文由 发表于 2022年2月19日 02:40:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/71178381.html
匿名

发表评论

匿名网友

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

确定