add fieldaligment
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
46
main.go
46
main.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"google.golang.org/protobuf/compiler/protogen"
|
||||
@@ -10,23 +11,25 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
flagDebug = flag.Bool("debug", false, "debug output")
|
||||
flagStandalone = flag.Bool("standalone", false, "generate file to standalone dir")
|
||||
flagComponents = flag.String("components", "micro|rpc|http|client|server|openapiv3", "specify components to generate")
|
||||
flagTagPath = flag.String("tag_path", "", "tag rewriting dir")
|
||||
flagOpenapiFile = flag.String("openapi_file", "apidocs.swagger.json", "openapi file name")
|
||||
flagHelp = flag.Bool("help", false, "display help message")
|
||||
flagSet = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
|
||||
flagDebug = flagSet.Bool("debug", false, "debug output")
|
||||
flagStandalone = flagSet.Bool("standalone", false, "generate file to standalone dir")
|
||||
flagFieldaligment = flagSet.Bool("fieldaligment", false, "align struct fields in generated code")
|
||||
flagComponents = flagSet.String("components", "micro|rpc|http|client|server|openapiv3", "specify components to generate")
|
||||
flagTagPath = flagSet.String("tag_path", "", "tag rewriting dir")
|
||||
flagOpenapiFile = flagSet.String("openapi_file", "apidocs.swagger.json", "openapi file name")
|
||||
flagHelp = flagSet.Bool("help", false, "display help message")
|
||||
)
|
||||
|
||||
func main() {
|
||||
opts := &protogen.Options{
|
||||
ParamFunc: flag.CommandLine.Set,
|
||||
ParamFunc: flagSet.Set,
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
flagSet.Parse(os.Args[1:])
|
||||
|
||||
if *flagHelp {
|
||||
flag.PrintDefaults()
|
||||
flagSet.PrintDefaults()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -36,11 +39,12 @@ func main() {
|
||||
}
|
||||
|
||||
type Generator struct {
|
||||
components string
|
||||
standalone bool
|
||||
debug bool
|
||||
tagPath string
|
||||
openapiFile string
|
||||
components string
|
||||
standalone bool
|
||||
debug bool
|
||||
fieldaligment bool
|
||||
tagPath string
|
||||
openapiFile string
|
||||
}
|
||||
|
||||
func (g *Generator) Generate(plugin *protogen.Plugin) error {
|
||||
@@ -49,12 +53,14 @@ func (g *Generator) Generate(plugin *protogen.Plugin) error {
|
||||
g.standalone = *flagStandalone
|
||||
g.debug = *flagDebug
|
||||
g.components = *flagComponents
|
||||
g.fieldaligment = *flagFieldaligment
|
||||
g.tagPath = *flagTagPath
|
||||
g.openapiFile = *flagOpenapiFile
|
||||
plugin.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
|
||||
|
||||
var genClient bool
|
||||
var genServer bool
|
||||
var genNone bool
|
||||
|
||||
if strings.Contains(g.components, "server") {
|
||||
genServer = true
|
||||
@@ -62,8 +68,11 @@ func (g *Generator) Generate(plugin *protogen.Plugin) error {
|
||||
if strings.Contains(g.components, "client") {
|
||||
genClient = true
|
||||
}
|
||||
if strings.Contains(g.components, "none") {
|
||||
genNone = true
|
||||
}
|
||||
if strings.Contains(g.components, "rpc") || strings.Contains(g.components, "http") {
|
||||
if !genServer && !genClient {
|
||||
if !genServer && !genClient && !genNone {
|
||||
genServer = true
|
||||
genClient = true
|
||||
}
|
||||
@@ -86,6 +95,8 @@ func (g *Generator) Generate(plugin *protogen.Plugin) error {
|
||||
err = g.chiGenerate(component, plugin)
|
||||
case "openapiv3":
|
||||
err = g.openapiv3Generate(component, plugin)
|
||||
case "none":
|
||||
break
|
||||
default:
|
||||
err = fmt.Errorf("unknown component: %s", component)
|
||||
}
|
||||
@@ -102,5 +113,10 @@ func (g *Generator) Generate(plugin *protogen.Plugin) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = g.fieldAlign(plugin); err != nil {
|
||||
plugin.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user