Same symptom as protoc-gen-go: unable to determine Go import path for "simple.proto"
For simple proto file with following content.
syntax="proto3"; package main; message Person { string name = 1; int32 age = 2; }
I am trying to generate go code for it using protoc. I run:
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative simple.proto
I receive following error:
protoc-gen-go: unable to determine Go import path for "simple.proto" Please specify either: • a "go_package" option in the .proto source file, or • a "M" argument on the command line.
All the answer there focus on the first option -- adding a "go_package" option in the .proto source file
, but I'm looking for the answer for the second option "a "M" argument on the command line".
Same as the comments under https://mcmap.net/q/370589/-correct-format-of-protoc-go_package
I'm looking for ways to change the module path via protoc
, to generate Go code for both a client and server that are part of different modules, I tried using go_opt=module
but it doesn't work with source_relative
.
Is there any ways to make it work by adding "a "M" argument on the command line", instead of adding a "go_package
" option in the .proto source file please?
Specifically, for the file of https://github.com/mmcc007/go/blob/master/examples/helloworld/helloworld/helloworld.proto
Here are my failed attempts:
$ protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative --proto_path=examples/helloworld/helloworld helloworld.proto
protoc-gen-go: unable to determine Go import path for "helloworld.proto"
. . .
--go_out: protoc-gen-go: Plugin failed with status code 1.
$ protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative --proto_path=examples/helloworld/helloworld --go_opt=Mhelloworld.proto=github.com/mmcc007/go/blob/master/examples/helloworld/helloworld helloworld.proto
protoc-gen-go-grpc: unable to determine Go import path for "helloworld.proto"
. . .
--go_out: protoc-gen-go: Plugin failed with status code 1.
protoc
doesn't care about modules, it only generates Go code. How you distribute that code is up to you – Selfemployedgo_package
? – Thyrsego_package
in the .proto source file, then it'll tie to a specific repo. But for such sample repo, if people to fork it elsewhere, it'll be more convenient to set the import path on cli for protoc, instead of hard-coding it. But regardless for any reason, if the 2nd option is available, I want to know how to make use of it. – Suppressive-M
option – Fungistatprotoc --go-grpc_out=fizz --go-grpc_opt="Mprotopath/buzz.proto=example.com/project/internal/proto;bar,module=example.com/project" protopath/buzz.proto
generatesfizz/internal/proto/buzz_grpc.pb.go
withpackage bar
(i know it is not sensible, only example) ref: github.com/protocolbuffers/protobuf-go/blob/v1.31.0/compiler/… – Blither