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.
34 lines
721 B
34 lines
721 B
package config |
|
|
|
import "github.com/spf13/viper" |
|
|
|
var ( |
|
defaultConfigPath = "config/config.toml" |
|
namespaceConfigPath = map[string]string{} |
|
) |
|
|
|
func SetDefaultConfigPath(confPath string) { |
|
defaultConfigPath = confPath |
|
} |
|
|
|
func SetNamespaceConfigPath(namespace string, confPath string) { |
|
namespaceConfigPath[namespace] = confPath |
|
} |
|
|
|
func getViper(namespace ...string) (v *viper.Viper, err error) { |
|
confPath := defaultConfigPath |
|
if len(namespace) > 0 { |
|
confPath = namespaceConfigPath[namespace[0]] |
|
} |
|
v, err = loadViper(confPath) |
|
return |
|
} |
|
|
|
func GetString(key string, namespace ...string) (value string, err error) { |
|
v, err := getViper(namespace...) |
|
if err != nil { |
|
return |
|
} |
|
value = v.GetString(key) |
|
return |
|
}
|
|
|