34 lines
627 B
Go
34 lines
627 B
Go
package core
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/fsnotify/fsnotify"
|
|
"github.com/spf13/viper"
|
|
"gitlink.org.cn/JointCloud/pcm-hpc/global"
|
|
)
|
|
|
|
func Viper() *viper.Viper {
|
|
|
|
v := viper.New()
|
|
v.SetConfigFile("config.yaml")
|
|
v.SetConfigType("yaml")
|
|
err := v.ReadInConfig()
|
|
if err != nil {
|
|
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
|
}
|
|
v.WatchConfig()
|
|
|
|
v.OnConfigChange(func(e fsnotify.Event) {
|
|
fmt.Println("config file changed:", e.Name)
|
|
if err = v.Unmarshal(&global.PCM_CONFIG); err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
})
|
|
|
|
if err = v.Unmarshal(&global.PCM_CONFIG); err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
|
|
return v
|
|
}
|