package config import ( "github.com/fsnotify/fsnotify" "github.com/spf13/viper" "log" ) type common struct { EsUrl string `mapstructure: "esUrl"` ServerUrl string `mapstructure: "serverUrl"` OrgName string `mapstructure: "orgName"` } var Options = &common{} func Init() { var err error viper.SetConfigType("yaml") viper.SetConfigName("esSync") viper.AddConfigPath("../config") viper.AddConfigPath("config") viper.AddConfigPath("") err = viper.ReadInConfig() if err != nil { log.Fatal("error on parsing configuration file", err) } viper.UnmarshalKey("common", Options) viper.WatchConfig() viper.OnConfigChange(func(in fsnotify.Event) { viper.UnmarshalKey("common", Options) }) }