protogen
BACKGROUND
Assume we have a big project like hdmall
, it has many sub projects, each sub project may use protobuf types defined in other sub projects,
the easiest way is put all proto files belong to different sub projects into same directory and just name it with different filename,
then compile all proto files into one package.
e,g:
proto/
...
order.proto
product.proto
...
will generate souce codes in autogen/pb
directory
autogen/
pb/
...
order.pb.go
product.pb.go
...
But the drawback is the final built binary file is too large, it will include all protobuf types defined in all proto files, which is not necessary.
INTRODUCTION
Fortunately, this tool is developed to find all protobuf types referenced in source codes, then extract the protobuf type definitions from center proto files repository, at last generate new proto source file which only contains protobuf types we needed.
INSTALL
go install github.com/hdget/protogen
USAGE
Usage:
[flags]
Flags:
-h, --help help for this command
--output-dir string output directory
--package string protobuf package name used in source code (default "pb")
--project-dir string project directory
--proto-dir string proto directory
--suffix string file suffix (default ".go")
protogen --project-dir=/tmp/project --proto-dir=/tmp/proto --output-dir=/tmp/project/proto
LIMITATION
- it only support find protobuf types from golang source codes
- it only supports gogo options
- 3rd party protobuf types only supported following:
google.protobuf.Any
hdsdk.protobuf