簡體   English   中英

go-grpc 導入“google/protobuf/struct.proto”未找到或有錯誤

[英]go-grpc Import “google/protobuf/struct.proto” was not found or had errors

我正在使用以下命令為 golang 生成原型代碼:

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”未定義。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM