-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
44 lines (38 loc) · 1.08 KB
/
config.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
42
43
44
package config
import (
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
"github.com/x-chain/baasconsole/baas-core/common/log"
"os"
)
var Config *viper.Viper
var logger = log.GetLogger("fabricengine.config", log.INFO)
func init() {
//监听改变动态跟新配置
go watchConfig()
//加载配置
loadConfig()
}
//监听配置改变
func watchConfig() {
viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) {
logger.Info("Config file changed:", e.Name)
//改变重新加载
loadConfig()
})
}
//加载配置
func loadConfig() {
viper.SetConfigName("feconfig") // name of kubeconfig file
viper.AddConfigPath(".") // optionally look for kubeconfig in the working directory
viper.AddConfigPath("/etc/baas") // path to look for the kubeconfig file in
err := viper.ReadInConfig() // Find and read the feconfig.yaml file
if err != nil { // Handle errors reading the kubeconfig file
logger.Errorf("Fatal error config file: %s \n", err)
os.Exit(-1)
}
//全局配置
Config = viper.GetViper()
logger.Infof("%v", Config.AllSettings())
}