go-grpc导入“google/protobuf/struct.proto”未找到或存在错误。

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

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../binstruct.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

huangapple
  • 本文由 发表于 2021年5月30日 01:42:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/67754241.html
匿名

发表评论

匿名网友

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

确定