go version: 去版本 go1.14 linux/amd64
去.mod
module [redacted]
go 1.14
require (
github.com/golang/protobuf v1.4.0-rc.2
google.golang.org/grpc v1.27.1
google.golang.org/protobuf v1.20.0 // indirect
)
Run Code Online (Sandbox Code Playgroud)
我正在运行以下命令:
protoc -I ./src/pbdefs/protos/ --go-grpc_out=. src/pbdefs/protos/*.proto
Run Code Online (Sandbox Code Playgroud)
从.proto文件生成我的 GRPC 输出文件,但出现错误
protoc-gen-go-grpc: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
--go-grpc_out: protoc-gen-go-grpc: Plugin failed with status code 1.
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 go grpc 构建示例应用程序,但无法使用“protoc”生成代码
已使用以下方法安装了所需的库/go 包:
也尝试过设置路径,但没有运气。
示例“原型”文件:
syntax = "proto3";
package greet;
option go_package="greetpb";
service GreetService{}
Run Code Online (Sandbox Code Playgroud)
错误消息:“protoc-gen-go:程序未找到或不可执行 --go_out:protoc-gen-go:插件失败,状态代码为 1。”
尝试编译我的原型 - 我需要编译它们以在我的反应应用程序中使用。但我收到这个错误。我运行命令如下:
cd src/main/proto && protoc -I=. *.proto --js_out=import_style=commonjs:. --grpc-web_out=import_style=commonjs,mode=grpcwebtext:.
Run Code Online (Sandbox Code Playgroud)
在哪里可以找到 protoc-gen-js?我没有遇到任何回购。
我刚开始玩谷歌原型.当我尝试编译proto-java示例中存在的proto文件时,它不会生成任何grpc文件.
proto文件, https://github.com/grpc/grpc-java/blob/master/examples/src/main/proto/hello_world.proto
终端输出,
rsonkhla @ raman-OptiPlex-9020:〜/ sandbox/grpc-java/examples $ protoc --version libprotoc 3.0.0 rsonkhla @ raman-OptiPlex-9020:〜/ sandbox/grpc-java/examples $ protoc --java_out = test/-I ../../ grpc-java/examples ../../grpc-java/examples/src/main/proto/hello_world.proto rsonkhla @ raman-OptiPlex-9020:〜/ sandbox/grpc-java/examples $ ls -R test/test /:io
test/io:grpc
test/io/grpc:示例
test/io/grpc/examples:helloworld
test/io/grpc/examples/helloworld:HelloRequest.java
HelloResponse.java HelloWorldProto.java HelloRequestOrBuilder.java HelloResponseOrBuilder.java
还有其他人遇到过这个问题吗?
我在 Go 中有一个现有项目,我正在使用协议缓冲区/gRPC。直到最近,该go_package选项还是可选的,并且生成的 Go 包名称将与 proto 包名称相同。
该文件位于项目根目录中。生成的代码文件 ( authenticator.pb.go) 位于同一位置。原型文件:
syntax = "proto3";
package authenticator;
service Authenticator {...}
Run Code Online (Sandbox Code Playgroud)
生成命令指定我要在同一目录中输出:
protoc --go_out=plugins=grpc:. authenticator.proto
Run Code Online (Sandbox Code Playgroud)
今天我拉取了新版本的协议缓冲区编译器和github.com/golang/protobuf/protoc-gen-go. 第一次运行时收到警告:
WARNING: Missing 'go_package' option in "authenticator.proto",
please specify it with the full Go package path as
a future release of protoc-gen-go will require this be specified.
See https://developers.google.com/protocol-buffers/docs/reference/go-generated#package for more information.
Run Code Online (Sandbox Code Playgroud)
建议的链接或多或少没用。但是教程更明确一点:
go_package 选项定义包的导入路径,该路径将包含此文件的所有生成代码。Go 包名称将是导入路径的最后一个路径组件。例如,我们的示例将使用包名称“tutorialpb”。
Run Code Online (Sandbox Code Playgroud)option go_package = "github.com/protocolbuffers/protobuf/examples/go/tutorialpb";
将此选项添加到 proto 文件并重新运行命令后,输出最终位于此路径中,相对于项目根目录。就像是:
$GOPATH/src/github.com/<org>/authenticator/github.com/<org>/authenticator/authenticator.pb.go
Run Code Online (Sandbox Code Playgroud)
我已经尝试了以下替代go_package名称:
.authenticator生成发生在正确的位置,但我得到了警告:
WARNING: …Run Code Online (Sandbox Code Playgroud) 我有包含以下内容的简单原型文件。
\nsyntax="proto3";\n\npackage main;\n\nmessage Person {\n string name = 1;\n int32 age = 2; \n}\nRun Code Online (Sandbox Code Playgroud)\n我正在尝试使用 protoc 为其生成 go 代码。我跑:
\nprotoc --go_out=. simple.proto\nRun Code Online (Sandbox Code Playgroud)\n我收到以下错误:
\nprotoc-gen-go: unable to determine Go import path for "simple.proto"\n\nPlease specify either:\n \xe2\x80\xa2 a "go_package" option in the .proto source file, or\n \xe2\x80\xa2 a "M" argument on the command line.\nRun Code Online (Sandbox Code Playgroud)\nmain.go,go.mod并且simple.proto位于同一文件夹中。和protoc都protoc-gen-go在 PATH 环境中定义。
我分叉一个前进模块,并希望用叉子在我的项目使用版本控制模块通过v1.12。我的代码不在我的GOPATH.
我的项目go.mod:
module github.com/me/myproj
go 1.12
require (
go.larrymyers.com/protoc-gen-twirp_typescript v0.0.0-20190605194555-ffbfe407b60f
)
replace go.larrymyers.com/protoc-gen-twirp_typescript => github.com/rynop/protoc-gen-twirp_typescript master
Run Code Online (Sandbox Code Playgroud)
protoc-gen-twirp_typescript 是一个工具protoc,所以这是我的tools.go:
// +build tools
package tools
import (
// protocol buffer compiler plugins
_ "github.com/golang/protobuf/protoc-gen-go"
_ "github.com/mwitkow/go-proto-validators/protoc-gen-govalidators"
_ "github.com/twitchtv/twirp/protoc-gen-twirp"
_ "github.com/rynop/protoc-gen-twirp_typescript"
)
Run Code Online (Sandbox Code Playgroud)
当我运行go mod tidy下载依赖项时,出现此错误:
go: finding github.com/rynop/protoc-gen-twirp_typescript master
go: finding github.com/rynop/protoc-gen-twirp_typescript latest
go: github.com/rynop/protoc-gen-twirp_typescript@v0.0.0-20190618203538-a346b5d9c8fb: parsing go.mod: unexpected module path "go.larrymyers.com/protoc-gen-twirp_typescript"
Run Code Online (Sandbox Code Playgroud)
我很难弄清楚protoc命令和 go 插件。
两者有什么不同:
protoc \
# Directory where you want the compiler to write your Go output.
--go_out=.
# vs ?
--go_opt=paths=source_relative
# vs ?
--go-grpc_out=.
# vs ?
--go-grpc_opt=paths=source_relative
Run Code Online (Sandbox Code Playgroud)
如果--go_opt生成
<name>.pb.go文件并--go-grpc_opt生成
<name>_grpc.pb.go文件为什么甚至有--go_out?
你能解释一下 protoc -文档没有说什么吗--go-grpc_opt?
并且甚至protoc -h不将 go 列为 OUT_DIR?
注意:我使用此文档安装
我按照这里找到的例子.但每当我输入命令"C:/ Program Files/protoc/bin/protoc"object_detection/protos/.proto --python_out =.我收到一个错误,上面写着object_detection/protos / .proto:没有这样的文件或目录.我无法创建名为*.proto的目录.所以我遗漏了一些关于如何做到这一点的基本信息.由于我找不到任何人抱怨这个问题,它必须非常简单.我正在使用Windows操作系统.
https://github.com/golang/protobuf
protoc-gen-go 是protoc中的插件,它为输入原型定义生成go绑定.
protoc-gen-go还有一个插件框架,它grpc是一个插件插件
https://github.com/golang/protobuf/tree/master/protoc-gen-go/grpc
$ protoc ./helloworld.proto --go_out=plugins=grpc:.
我可以编写自己的插件并将其与grpc插件一起调用吗?
$ protoc ./helloworld.proto --go_out=plugins=grpc+myplugin:.
我是否需要强制将我的插件构建到protoc-gen-go中?如果没有,那么protoc-gen-go将如何找到myplugin?
protoc ×10
go ×5
grpc ×5
grpc-go ×2
go-modules ×1
grpc-web ×1
plugins ×1
proto ×1
python ×1
tensorflow ×1