在golang中的protobuf编译中指定基本包

I've got golang package github.com/user/protoapp, in this package I have folder proto containing protobuf files.

github.com/user/protoapp
|-proto
|-proto/app1
|-proto/app2

proto files in app1 and app2 have corresponing packages app1 and app;

Proto file from proto/app1 is importing file from proto/app2 like import "app2/messages.proto"; after compillation in app1.pb.go it becomes import app2 and protoapp fails to compile. How do I make imports in *.pb.go files become import "github.com/user/protoapp/proto/app2" rather than import "app2"?

you need to make your import in your proto a fully qualified path like in Go:

instead of import "app2/messages.proto";

try import "github.com/user/protoapp/proto/app2/messages.proto";

Never specify the half path "/app2/messages.proto" it won't be work.

  1. Specify the full import name
import "github.com/user/protoapp/proto/app2/messages.proto";

and

  1. Do define with the package name
//if we does'nt add package we define it will show error
package messagedata;