You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.5 KiB

13 years ago
  1. package util
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/glog"
  4. "github.com/spf13/viper"
  5. )
  6. type Configuration interface {
  7. GetString(key string) string
  8. GetBool(key string) bool
  9. GetInt(key string) int
  10. GetStringSlice(key string) []string
  11. }
  12. func LoadConfiguration(configFileName string, required bool) (loaded bool) {
  13. // find a filer store
  14. viper.SetConfigName(configFileName) // name of config file (without extension)
  15. viper.AddConfigPath(".") // optionally look for config in the working directory
  16. viper.AddConfigPath("$HOME/.seaweedfs") // call multiple times to add many search paths
  17. viper.AddConfigPath("/etc/seaweedfs/") // path to look for the config file in
  18. glog.V(1).Infof("Reading %s.toml from %s", configFileName, viper.ConfigFileUsed())
  19. if err := viper.MergeInConfig(); err != nil { // Handle errors reading the config file
  20. glog.V(0).Infof("Reading %s: %v", viper.ConfigFileUsed(), err)
  21. if required {
  22. glog.Fatalf("Failed to load %s.toml file from current directory, or $HOME/.seaweedfs/, or /etc/seaweedfs/"+
  23. "\n\nPlease follow this example and add a filer.toml file to "+
  24. "current directory, or $HOME/.seaweedfs/, or /etc/seaweedfs/:\n"+
  25. " https://github.com/chrislusf/seaweedfs/blob/master/weed/%s.toml\n"+
  26. "\nOr use this command to generate the default toml file\n"+
  27. " weed scaffold -config=%s -output=.\n\n\n",
  28. configFileName, configFileName, configFileName)
  29. } else {
  30. return false
  31. }
  32. }
  33. return true
  34. }