I I don't understand the purpose of the go_package_prefix code snippet in generating protobuf files
version: v1
managed:
enabled: true
go_package_prefix:
default: github.com/imsobad/grpc-gateway-demo
except:
- buf.build/googleapis/googleapis
plugins:
- plugin: buf.build/protocolbuffers/go:v1.30.0
out: gen/go
opt:
- paths=source_relative
- plugin: buf.build/grpc/go:v1.3.0
out: gen/go
opt:
- paths=source_relative
- require_unimplemented_servers=false
- plugin: grpc-gateway
out: gen/go
opt:
- paths=source_relative
- generate_unbound_methods=true
I want to understand how the command "go_package_prefix" work
For anyone still interested, according to the docs: https://buf.build/docs/generate/managed-mode/ managed mode helps you, or other developers manage .proto files in your "buf" project, instead of managing them individually. The docs should explain that better than me though. So read that. Really. It is nicely documented.
However I can provide you with an example.
Lets say you have a .proto file, like this:
Notice the package specification, and the lack of go_package option.
When using managed mode with default prefix, your package is essentially prefixed with your specified prefix option. E.g. you could simply specify
com.your.domain/project
asgo_package_prefix
default and then, all of your compiled proto potentially relying on these definitions will havecom.your.domain/project
as a prefix in their imports (no need to specify go_package for every individual protofile).Hopefully, this explains some of the purpose behind the
go_package_prefix
option.Note: I am not a native speaker, so in case my wording or explanation is off-throwing, please feel free to correct me.