【问题标题】:Unable to figure out missing protoc command from udemy course无法从 udemy 课程中找出丢失的 protoc 命令
【发布时间】:2019-01-16 12:36:53
【问题描述】:

问题:

上周我一直在学习 Udemy 上的 Golang 微服务课程,但遇到了问题。

基本上,讲师通过编写 .proto 文件向我们介绍了 Go-Micro 和 RPC。现在我对 GRPC 有了一些经验,但对 Go-Micro 没有。问题是讲师没有显示实际的protoc 命令和最终的标志,而只是刷过它。我以为这将是一个微不足道的命令,但在运行 protoc greeter.proto go_out=. 之后,我错过了 client sn-ps..

预期:

pb.go 文件看起来与the instructor's 相同,在 pb.go 文件中包含客户端和服务器 sn-ps。

实际:

缺少客户端 sn-ps。

命令运行:

protoc greeter.proto go_out=.

代码:

.proto 文件:

syntax = "proto3";

service Greeter { 
    rpc Hello(HelloRequest) returns (HelloResponse) {}
}

message HelloRequest {
    string name = 1;
}

message HelloResponse {
    string greeting = 2;
}

【问题讨论】:

    标签: go protocol-buffers go-micro


    【解决方案1】:

    希望这会有所帮助:

    第一个是生成proto文件,第二个是反向代理

    在这个 filename.proto 中:- filename 是你的文件名

    # Generate proto
    protoc -I/usr/local/include -I.  -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=google/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api,plugins=grpc:. filename.proto
    
    #Reverse Proxy For REST
    protoc -I/usr/local/include -I. -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:. filename.proto
    

    【讨论】:

      【解决方案2】:

      我使用这个命令:

      protoc --proto_path=$GOPATH/src:. --micro_out=. --go_out=plugins=grpc:. *.proto 
      

      来自原始文件所在的目录。它生成服务以及客户端代码。我在 go-micro github 存储库和 go-micro 网站的众多示例之一中找到了此命令。

      不过,这适用于 grpc,但这个想法还可以。

      【讨论】:

      • 是的,所以我用 GRPC 也能正常工作,但服务器的定义与教师使用的完全不同。不同的界面等,这绝对是可行的,但不是我想要的。
      • 接口对于生成代码所必须使用的命令无关紧要。当然,我的项目中也有完全不同的接口,也有非常复杂的接口。我没有遇到任何问题。我不确定您在寻找什么,您必须在问题中更好地解释这一点。
      猜你喜欢
      • 2019-03-26
      • 1970-01-01
      • 2020-04-03
      • 1970-01-01
      • 2020-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-10
      相关资源
      最近更新 更多