|
@@ -7,27 +7,26 @@ import (
|
|
|
type any interface{}
|
|
|
|
|
|
var (
|
|
|
- name = "config"
|
|
|
- configType = "yaml"
|
|
|
- path = "."
|
|
|
+ defaultName = "config"
|
|
|
+ defaultConfigType = "yaml"
|
|
|
+ defaultPath = "."
|
|
|
)
|
|
|
|
|
|
-func init() {
|
|
|
- Init()
|
|
|
-}
|
|
|
+//func init() {
|
|
|
+// Init()
|
|
|
+//}
|
|
|
|
|
|
func Init() {
|
|
|
//引入viper配置文件
|
|
|
- viper.SetConfigName(name) //name := lib.AppName()
|
|
|
- viper.SetConfigType(configType)
|
|
|
- viper.AddConfigPath(path)
|
|
|
+ viper.SetConfigName(defaultName) //defaultName := lib.AppName()
|
|
|
+ viper.SetConfigType(defaultConfigType)
|
|
|
+ viper.AddConfigPath(defaultPath)
|
|
|
}
|
|
|
|
|
|
-func SetConfigInfo(n, c, p string) {
|
|
|
- name = n
|
|
|
- configType = c
|
|
|
- path = p
|
|
|
- Init()
|
|
|
+func SetConfigInfo(name, suffix, path string) {
|
|
|
+ viper.SetConfigName(name) //defaultName := lib.AppName()
|
|
|
+ viper.SetConfigType(suffix)
|
|
|
+ viper.AddConfigPath(path)
|
|
|
}
|
|
|
|
|
|
func Load() error {
|
|
@@ -62,3 +61,7 @@ func GetStringSlice(module string, key string) []string {
|
|
|
return viper.GetStringSlice(module + "." + key)
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+func Set(module, key string, value any) {
|
|
|
+ viper.Set(module+"."+key, key)
|
|
|
+}
|