(configFileName string, required bool)
| 39 | } |
| 40 | |
| 41 | func LoadConfiguration(configFileName string, required bool) (loaded bool) { |
| 42 | |
| 43 | // find a filer store |
| 44 | viper.SetConfigName(configFileName) // name of config file (without extension) |
| 45 | viper.AddConfigPath(ResolvePath(ConfigurationFileDirectory.String())) // path to look for the config file in |
| 46 | viper.AddConfigPath(".") // optionally look for config in the working directory |
| 47 | viper.AddConfigPath("$HOME/.seaweedfs") // call multiple times to add many search paths |
| 48 | viper.AddConfigPath("/usr/local/etc/seaweedfs/") // search path for bsd-style config directory in |
| 49 | viper.AddConfigPath("/etc/seaweedfs/") // path to look for the config file in |
| 50 | |
| 51 | if err := viper.MergeInConfig(); err != nil { // Handle errors reading the config file |
| 52 | if strings.Contains(err.Error(), "Not Found") { |
| 53 | glog.V(1).Infof("Reading %s: %v", viper.ConfigFileUsed(), err) |
| 54 | } else { |
| 55 | // If the config is required, fail immediately |
| 56 | if required { |
| 57 | glog.Fatalf("Reading %s: %v", viper.ConfigFileUsed(), err) |
| 58 | } |
| 59 | // If the config is optional, log a warning but don't crash |
| 60 | glog.Warningf("Reading %s: %v. Skipping optional configuration.", viper.ConfigFileUsed(), err) |
| 61 | } |
| 62 | if required { |
| 63 | glog.Fatalf("Failed to load %s.toml file from current directory, or $HOME/.seaweedfs/, or /etc/seaweedfs/"+ |
| 64 | "\n\nPlease use this command to generate the default %s.toml file\n"+ |
| 65 | " weed scaffold -config=%s -output=.\n\n\n", |
| 66 | configFileName, configFileName, configFileName) |
| 67 | } |
| 68 | return false |
| 69 | } |
| 70 | glog.V(1).Infof("Reading %s.toml from %s", configFileName, viper.ConfigFileUsed()) |
| 71 | |
| 72 | return true |
| 73 | } |
| 74 | |
| 75 | type ViperProxy struct { |
| 76 | *viper.Viper |
no test coverage detected