MCPcopy
hub / github.com/seaweedfs/seaweedfs / LoadConfiguration

Function LoadConfiguration

weed/util/config.go:41–73  ·  view source on GitHub ↗
(configFileName string, required bool)

Source from the content-addressed store, hash-verified

39}
40
41func 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
75type ViperProxy struct {
76 *viper.Viper

Callers 15

runWithOptionsFunction · 0.92
DoMethod · 0.92
runServerFunction · 0.92
runMasterFollowerFunction · 0.92
runVolumeFunction · 0.92
runMiniFunction · 0.92
startMiniWorkerFunction · 0.92
startMiniPluginWorkerFunction · 0.92
runFilerBackupFunction · 0.92
runShellFunction · 0.92
runAdminFunction · 0.92

Calls 8

VFunction · 0.92
FatalfFunction · 0.92
WarningfFunction · 0.92
ResolvePathFunction · 0.85
ContainsMethod · 0.80
InfofMethod · 0.80
StringMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected