mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2024-12-29 12:17:48 +00:00
ffbc5fdf5a
Add a generator option that strips a prefix from the generated filenames. Consider this case: We have google/protobuf/empty.proto, with a go_package option of "google.golang.org/protobuf/types/known/emptypb". We want to generate the code for this file, placing it into the appropriate directory of our repository. In the default mode used by the code generator (paths=import), the generator outputs the file: google.golang.org/protobuf/types/known/emptypb/empty.pb.go This is close to what we want, but has an unnecessary "google.golang.org/protobuf/" prefix. In the GOPATH world, we could pass --go_out=$GOPATH to protoc and get a generated file in the desired location, but this path is not useful in the modules world. The 'module' option allows us to strip off the module prefix, generating the desired filename (types/known/emptypb/empty.pb.go): protoc --go_out=. --go_opt=module=google.golang.org/protobuf google/protobuf/empty.proto The module name must be an exact, character-for-character match. This matches protoc's file handling in general. Default to and require the paths=import option when module= is specified, since it only makes sense when combined with it. Updates golang/protobuf#992. Change-Id: Idbfe4826b6c0ece30d64dbc577131a4f16391936 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/219298 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com> |
||
---|---|---|
.. | ||
protogen_test.go | ||
protogen.go |