add gorilla and chi helpers

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-02-22 23:42:49 +03:00
parent 2c001628ff
commit c865c1f665
4 changed files with 275 additions and 21 deletions

39
main.go
View File

@@ -8,40 +8,39 @@ import (
"google.golang.org/protobuf/compiler/protogen"
)
var (
flags flag.FlagSet
flagDebug *bool
flagComponents *string
flagPaths *string
flagModule *string
)
func init() {
flagDebug = flags.Bool("debug", false, "")
flagComponents = flags.String("components", "micro", "")
flagPaths = flag.String("paths", "", "")
flagModule = flag.String("module", "", "")
}
func main() {
var flags flag.FlagSet
flagDebug := flags.Bool("debug", false, "")
flagComponents := flags.String("components", "micro", "")
flagPaths := flag.String("paths", "", "")
flagModule := flag.String("module", "", "")
opts := &protogen.Options{
ParamFunc: flags.Set,
}
g := &Generator{
debug: *flagDebug,
components: strings.Split(*flagComponents, "|"),
paths: *flagPaths,
module: *flagModule,
}
g := &Generator{}
opts.Run(g.Generate)
}
type Generator struct {
debug bool
components []string
paths string
module string
}
func (g *Generator) Generate(plugin *protogen.Plugin) error {
var err error
// Protoc passes a slice of File structs for us to process
for _, component := range g.components {
for _, component := range strings.Split(*flagComponents, "|") {
switch component {
case "micro":
err = g.microGenerate(component, plugin)
@@ -51,6 +50,10 @@ func (g *Generator) Generate(plugin *protogen.Plugin) error {
err = g.rpcGenerate(component, plugin)
case "openapi", "swagger":
err = g.openapiGenerate(component, plugin)
case "gorilla":
err = g.gorillaGenerate(component, plugin)
case "chi":
err = g.chiGenerate(component, plugin)
default:
err = fmt.Errorf("unknown component: %s", component)
}