forked from tencentyun/tsf-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (37 loc) · 820 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"flag"
"fmt"
"github.com/hisonsoft/tsf-go/config"
)
type AppConfig struct {
Stone string `yaml:"stone"`
Auth Auth `yaml:"auth"`
}
type Auth struct {
Key string `yaml:"key"`
}
func main() {
flag.Parse()
cfg := config.GetConfig()
value, _ := cfg.GetString("stone")
fmt.Println("stone:", value)
// 监听应用配置文件变化
config.WatchConfig(func(conf *config.Config) {
var appCfg AppConfig
err := conf.Unmarshal(&appCfg)
if err != nil {
panic(err)
}
fmt.Printf("appConfig: %v\n", appCfg)
})
// 订阅全局配置(命名空间纬度)
config.WatchConfig(func(conf *config.Config) {
var gloablCfg AppConfig
err := conf.Unmarshal(&gloablCfg)
if err != nil {
panic(err)
}
fmt.Printf("globalConfig: %v\n", gloablCfg)
}, config.WithGlobal(true))
}