-1

I have two git repositories:

common this repository contains protobuf files (.proto), these files should be fetched via git submodule init from other vendor repository. There are also go files with directive: //go:generate protoc --proto_path=a/xxx --go_out=. --go_opt=paths=source_relative a/xxx/b.proto

main this repository contains main project, which imports the package from common. Then I call git submodule update --init and the go generate. After generate i can see the log: go: finding github.xxx.com/xxx latest

but the main go file shows some problems: build github.xxx.com/main: cannot load github.xxx.com/xxx/proto: module github.xxx.com/common@latest found, but does not contains package github.xxx.com/xxx/proto

It seems that the go generate command doesn't generate proto files. I think if I import something then these files are somewhere in cache. I'm not sure if my approach is possible.

Could you tell me if this solution is feasible or what I should change.

user3930618
  • 99
  • 2
  • 11
  • 2
    Typically your `.proto` repo should have the generated `.pb.go` files checked in, not only to avoid a complicated build process, but also to ensure each importer gets a consistent version. – colm.anseo Sep 01 '20 at 13:07
  • I think this is an interesting question and, I've not found (!?) good best practices on this. @colm.anseo answer is good because `go get` works but it has a couple of caveats: first, this would require confirming that the generated files still match the protos which can only really be done by rerunning protoc; second, as a cross-platform tool, what if the user wants e.g. Rust or Java sources? – DazWilkin Sep 01 '20 at 19:35
  • You need all the sources but you can't `go get` (without Go sources). You could clone the protos repo standalone. Then protoc-generate the sources in it. Then use a replace directive in your main's go.mod to point to the local replica (with sources)? This keeps the projects distinct (which they are; possibly 3rd-party repos too), ensures you're getting the protos as-is (Go) and avoids encumbering your project with the separate module. – DazWilkin Sep 01 '20 at 19:36

1 Answers1

0

ok, my solution is project layout like this: https://github.com/golang-standards/project-layout

there I have more main.go files inside cmd folder. In this way I have only one module and inside the module I can have different applicaions. I think it's very cool solution.

user3930618
  • 99
  • 2
  • 11