2021-02-17 17:14:47 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"google.golang.org/protobuf/compiler/protogen"
|
|
|
|
"google.golang.org/protobuf/types/pluginpb"
|
|
|
|
)
|
|
|
|
|
2021-07-25 00:29:09 +08:00
|
|
|
var (
|
|
|
|
showVersion = flag.Bool("version", false, "print the version and exit")
|
|
|
|
omitempty = flag.Bool("omitempty", true, "omit if google.api is empty")
|
|
|
|
)
|
2021-02-17 17:14:47 +08:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
if *showVersion {
|
2021-11-19 17:14:24 +08:00
|
|
|
fmt.Printf("protoc-gen-go-http %v\n", release)
|
2021-02-17 17:14:47 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
protogen.Options{
|
2021-06-14 11:43:22 +08:00
|
|
|
ParamFunc: flag.CommandLine.Set,
|
2021-02-17 17:14:47 +08:00
|
|
|
}.Run(func(gen *protogen.Plugin) error {
|
|
|
|
gen.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
|
|
|
|
for _, f := range gen.Files {
|
|
|
|
if !f.Generate {
|
|
|
|
continue
|
|
|
|
}
|
2021-06-14 11:43:22 +08:00
|
|
|
generateFile(gen, f, *omitempty)
|
2021-02-17 17:14:47 +08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|