Skip to content

Commit c1e5299

Browse files
authored
fix: fix the loading of config (#210)
1 parent e44c195 commit c1e5299

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

config/config.go

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ import (
2727
"gopkg.in/yaml.v3"
2828
)
2929

30+
func init() {
31+
err := LoadConfig()
32+
if err != nil {
33+
panic(err)
34+
}
35+
}
36+
3037
type RawConfig struct {
3138
Ref map[string]interface{} `yaml:"ref"`
3239
Debug bool `yaml:"debug"`
@@ -101,6 +108,8 @@ func GetRef(name string) *RefConfig {
101108
return refConfig
102109
}
103110

111+
// LoadConfig by default, config will load only once when the program is invoked, also the same for each plugin
112+
// 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.
104113
func LoadConfig() error {
105114
config, err := initConfig()
106115
if err != nil {

main.go

-6
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
"runtime/debug"
2121
"runtime/pprof"
2222

23-
"github.com/cloudwego/thriftgo/config"
24-
2523
"time"
2624

2725
"github.com/cloudwego/thriftgo/args"
@@ -41,10 +39,6 @@ var (
4139
var debugMode bool
4240

4341
func init() {
44-
err := config.LoadConfig()
45-
if err != nil {
46-
panic(err)
47-
}
4842
_ = g.RegisterBackend(new(golang.GoBackend))
4943
// export THRIFTGO_DEBUG=1
5044
debugMode = os.Getenv("THRIFTGO_DEBUG") == "1"

0 commit comments

Comments
 (0)