diff options
| author | Chris Lu <chris.lu@gmail.com> | 2019-06-05 01:30:24 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2019-06-05 01:30:24 -0700 |
| commit | ede876cfdb0116557dd197a7951957dab6745c24 (patch) | |
| tree | 50bab90cbf757bb0ad6b3239ed938dfd8d55874e /weed/util/config.go | |
| parent | b9e138713c8e2f53cf96132b5ff077ded67c5c20 (diff) | |
| download | seaweedfs-ede876cfdb0116557dd197a7951957dab6745c24.tar.xz seaweedfs-ede876cfdb0116557dd197a7951957dab6745c24.zip | |
periodic scripts exeuction from leader master
Diffstat (limited to 'weed/util/config.go')
| -rw-r--r-- | weed/util/config.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/weed/util/config.go b/weed/util/config.go index 77cab3019..1ea833d1f 100644 --- a/weed/util/config.go +++ b/weed/util/config.go @@ -1,5 +1,10 @@ package util +import ( + "github.com/chrislusf/seaweedfs/weed/glog" + "github.com/spf13/viper" +) + type Configuration interface { GetString(key string) string GetBool(key string) bool @@ -8,3 +13,32 @@ type Configuration interface { GetFloat64(key string) float64 GetStringSlice(key string) []string } + +func LoadConfiguration(configFileName string, required bool) (loaded bool) { + + // find a filer store + viper.SetConfigName(configFileName) // name of config file (without extension) + viper.AddConfigPath(".") // optionally look for config in the working directory + viper.AddConfigPath("$HOME/.seaweedfs") // call multiple times to add many search paths + viper.AddConfigPath("/etc/seaweedfs/") // path to look for the config file in + + glog.V(1).Infof("Reading %s.toml from %s", configFileName, viper.ConfigFileUsed()) + + if err := viper.MergeInConfig(); err != nil { // Handle errors reading the config file + glog.V(0).Infof("Reading %s: %v", viper.ConfigFileUsed(), err) + if required { + glog.Fatalf("Failed to load %s.toml file from current directory, or $HOME/.seaweedfs/, or /etc/seaweedfs/"+ + "\n\nPlease follow this example and add a filer.toml file to "+ + "current directory, or $HOME/.seaweedfs/, or /etc/seaweedfs/:\n"+ + " https://github.com/chrislusf/seaweedfs/blob/master/weed/%s.toml\n"+ + "\nOr use this command to generate the default toml file\n"+ + " weed scaffold -config=%s -output=.\n\n\n", + configFileName, configFileName, configFileName) + } else { + return false + } + } + + return true + +} |
