add gorilla and chi helpers
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
39
main.go
39
main.go
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user