英文:
go-grpc Import "google/protobuf/struct.proto" was not found or had errors
问题
我正在使用以下命令生成用于Golang的proto代码:
protoc --go_out=../generated --go_opt=paths=source_relative \
--go-grpc_out=../generated --go-grpc_opt=paths=source_relative \
*.proto
我正在使用内置的google/protobuf/struct.proto来处理非结构化数据。然而,我遇到了一个错误,提示"google.protobuf.Struct"未定义。
英文:
I'm using following command to generate proto code for golang:
protoc --go_out=../generated --go_opt=paths=source_relative \
--go-grpc_out=../generated --go-grpc_opt=paths=source_relative \
*.proto
I'm using in-built google/protobuf/struct.proto for unstructured data. However, I'm getting an error saying "google.protobuf.Struct" is not defined.
答案1
得分: 1
protoc 包括 ./bin 和 ./include 目录。
./include 目录应该包含例如 google/protobuf/struct.proto。
如果你正确设置了 PATH 为 ./protoc../bin,struct.proto 应该被包含在编译中。
示例
go.mod:
module github.com/some/test
go 1.16
require google.golang.org/protobuf v1.26.0
test.proto:
syntax = "proto3";
package test;
import "google/protobuf/struct.proto";
option go_package = "github.com/some/test;test";
message SomeRequest {
google.protobuf.Struct some_struct = 1;
}
然后执行:
protoc \
--go_out=. \
--go_opt=module=github.com/some/test \
test.proto
英文:
protoc comprises ./bin and ./include directories.
The ./include should include e.g. google/protobuf/struct.proto.
If you're correctly setting the PATH to ./protoc../bin, struct.proto should be included in the compilation.
Example
go.mod:
module github.com/some/test
go 1.16
require google.golang.org/protobuf v1.26.0
test.proto:
syntax = "proto3";
package test;
import "google/protobuf/struct.proto";
option go_package = "github.com/some/test;test";
message SomeRequest {
google.protobuf.Struct some_struct = 1;
}
Then:
protoc \
--go_out=. \
--go_opt=module=github.com/some/test \
test.proto
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论