| | |
| | | package config |
| | | |
| | | import ( |
| | | "github.com/fsnotify/fsnotify" |
| | | "github.com/spf13/viper" |
| | | "log" |
| | | ) |
| | | |
| | | type servUrls struct { |
| | | type common struct { |
| | | EsUrl string `mapstructure: "esUrl"` |
| | | ServerUrl string `mapstructure: "serverUrl"` |
| | | OrgName string `mapstructure: "orgName"` |
| | | } |
| | | |
| | | var ServUrls = &servUrls{} |
| | | var Options = &common{} |
| | | |
| | | func Init(env string) { |
| | | func Init() { |
| | | var err error |
| | | viper.SetConfigType("yaml") |
| | | viper.SetConfigName(env) |
| | | 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("servUrls", ServUrls) |
| | | |
| | | viper.UnmarshalKey("common", Options) |
| | | viper.WatchConfig() |
| | | viper.OnConfigChange(func(in fsnotify.Event) { |
| | | viper.UnmarshalKey("common", Options) |
| | | }) |
| | | } |