From 9cb11bd641cfd72e9d06136d518a70bbf45d321c Mon Sep 17 00:00:00 2001 From: HeyJavaBean Date: Wed, 12 Jun 2024 15:18:55 +0800 Subject: [PATCH 1/3] fix: fix the loading of config --- config/config.go | 9 +++++++++ main.go | 6 ------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index 9cae7a4..67e4db3 100644 --- a/config/config.go +++ b/config/config.go @@ -27,6 +27,13 @@ import ( "gopkg.in/yaml.v3" ) +func init() { + err := LoadConfig() + if err != nil { + panic(err) + } +} + type RawConfig struct { Ref map[string]interface{} `yaml:"ref"` Debug bool `yaml:"debug"` @@ -101,6 +108,8 @@ func GetRef(name string) *RefConfig { return refConfig } +// LoadConfig by default, config will load only once when the program is invoked, also the same for each plugin +// but for sdk mode, config should be reloaded each time when the sdk is called. so we provide this api and manually call this in sdk mode. func LoadConfig() error { config, err := initConfig() if err != nil { diff --git a/main.go b/main.go index e05036a..cc7245f 100644 --- a/main.go +++ b/main.go @@ -20,8 +20,6 @@ import ( "runtime/debug" "runtime/pprof" - "github.com/cloudwego/thriftgo/config" - "time" "github.com/cloudwego/thriftgo/args" @@ -41,10 +39,6 @@ var ( var debugMode bool func init() { - err := config.LoadConfig() - if err != nil { - panic(err) - } _ = g.RegisterBackend(new(golang.GoBackend)) // export THRIFTGO_DEBUG=1 debugMode = os.Getenv("THRIFTGO_DEBUG") == "1" From ede0523a55269a69ebe808c34915f479bd055dc3 Mon Sep 17 00:00:00 2001 From: HeyJavaBean Date: Tue, 25 Jun 2024 11:42:58 +0800 Subject: [PATCH 2/3] optimize: remove useless ref --- generator/golang/templates/ref/ref_tpl.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/generator/golang/templates/ref/ref_tpl.go b/generator/golang/templates/ref/ref_tpl.go index 3b732cd..4397c13 100644 --- a/generator/golang/templates/ref/ref_tpl.go +++ b/generator/golang/templates/ref/ref_tpl.go @@ -43,10 +43,6 @@ import ( ` + structRef + ` {{- end}} -{{- range .Services}} -` + processorRef + ` -{{- end}} - {{- InsertionPoint "eof"}} ` From 385866b5306449420298c40c4f32015e1f034564 Mon Sep 17 00:00:00 2001 From: HeyJavaBean Date: Tue, 25 Jun 2024 14:17:59 +0800 Subject: [PATCH 3/3] fix: fix help hint --- args/args.go | 13 ++++++------- main.go | 4 +++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/args/args.go b/args/args.go index add7da4..34cb1f8 100644 --- a/args/args.go +++ b/args/args.go @@ -248,13 +248,12 @@ Options: Available generators (and options): go `) - //// print backend options - //for _, b := range g.AllBackend() { - // name, lang := b.Name(), b.Lang() - // println(fmt.Sprintf(" %s (%s):", name, lang)) - // println(align(b.Options())) - //} - println() + // print backend options + b := new(golang.GoBackend) + name, lang := b.Name(), b.Lang() + println(fmt.Sprintf(" %s (%s):", name, lang)) + println(align(b.Options())) + } // align the help strings for plugin options. diff --git a/main.go b/main.go index cc7245f..1bac82e 100644 --- a/main.go +++ b/main.go @@ -46,7 +46,9 @@ func init() { func check(err error) { if err != nil { - println(err.Error()) + if err.Error() != "flag: help requested" { + println(err.Error()) + } os.Exit(2) } }