buf icon indicating copy to clipboard operation
buf copied to clipboard

Support configuration for `go_package_prefix` package name

Open doriable opened this issue 3 years ago • 1 comments

Currently, we are create a package declaration based on the final two elements of the path of the package:

If the Protobuf file's package declaration conforms to the PACKAGE_VERSION_SUFFIX lint rule, the final two path elements are concatenated and included after the ; element in the go_package result. The above example generates a Go package with a package declaration equal to weatherv1, which enables you to import Go definitions from a variety of generated packages that would otherwise collide (a lot of Protobuf packages contain the v1 suffix).

https://docs.buf.build/configuration/v1/buf-gen-yaml#default

This may not be desirable for all project structures, in particular ones that are more deeply nested. We should consider a configuration under go_package_prefix that allows the user some way to specify depth of the package tag, e.g.

version: v1
managed:
  enabled: true
  go_package_prefix:
    default: github.com/acme/weather/private/gen/proto/go
    package_name_depth: 3 <default 2>

We could also consider exposing per package overrides for this as well.

doriable avatar Jul 05 '22 19:07 doriable

I think, this is a proper place to discuss the implementation details as discussed in the: https://github.com/bufbuild/buf/pull/2343#issuecomment-1664171302.

kucjac avatar Aug 03 '23 17:08 kucjac