protoc-gen-go: unable to determine Go import path for "simple.proto"

Issue

I have 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=. 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.

main.go, go.mod and simple.proto is in the same folder. Both protoc and protoc-gen-go are defined in PATH enviroement.

Solution

You are missing option go_package.

The name you will give to option go_package will be the name of the package that will be generated by the protoc. By doing so, you can import thus access message fields.

Answered By – blockByblock

Answer Checked By – Robin (GoLangFix Admin)

Leave a Reply

Your email address will not be published.