0

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.

SaiNageswar S
  • 1,203
  • 13
  • 22

1 Answers1

1

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
DazWilkin
  • 32,823
  • 5
  • 47
  • 88