Skip to content

Commit

Permalink
feat: support hooks before and after load config
Browse files Browse the repository at this point in the history
  • Loading branch information
sysulq committed Jun 9, 2022
1 parent ea501ce commit f38db3d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/conf/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/BurntSushi/toml"
"github.com/douyu/jupiter/pkg/flag"
"github.com/douyu/jupiter/pkg/hooks"
)

const DefaultEnvPrefix = "APP_"
Expand All @@ -30,6 +31,8 @@ func init() {
}})

flag.Register(&flag.StringFlag{Name: "config", Usage: "--config=config.toml", Action: func(key string, fs *flag.FlagSet) {
hooks.Do(hooks.Stage_BeforeLoadConfig)

var configAddr = fs.String(key)
log.Printf("read config: %s", configAddr)
datasource, err := NewDataSource(configAddr)
Expand All @@ -40,6 +43,8 @@ func init() {
log.Fatalf("load config from datasource[%s] failed: %v", configAddr, err)
}
log.Printf("load config from datasource[%s] completely!", configAddr)

hooks.Do(hooks.Stage_AfterLoadConfig)
}})

flag.Register(&flag.StringFlag{Name: "config-tag", Usage: "--config-tag=mapstructure", Default: "mapstructure", Action: func(key string, fs *flag.FlagSet) {
Expand Down

0 comments on commit f38db3d

Please sign in to comment.