|
@@ -6,18 +6,28 @@ import (
|
|
|
|
|
|
type any interface{}
|
|
|
|
|
|
+var (
|
|
|
+ name = "config"
|
|
|
+ configType = "yaml"
|
|
|
+ path = "."
|
|
|
+)
|
|
|
+
|
|
|
func init() {
|
|
|
- //引入viper配置文件
|
|
|
- viper.SetConfigName("iot-master") //name := lib.AppName()
|
|
|
- viper.SetConfigType("yaml")
|
|
|
- viper.AddConfigPath(".")
|
|
|
- //viper.SetEnvPrefix("database")
|
|
|
+ Init()
|
|
|
+}
|
|
|
|
|
|
- //绑定命令行参数
|
|
|
- //_ = viper.BindPFlags(pflag.CommandLine)
|
|
|
+func Init() {
|
|
|
+ //引入viper配置文件
|
|
|
+ viper.SetConfigName(name) //name := lib.AppName()
|
|
|
+ viper.SetConfigType(configType)
|
|
|
+ viper.AddConfigPath(path)
|
|
|
+}
|
|
|
|
|
|
- //数据目录
|
|
|
- viper.SetDefault("data", "data")
|
|
|
+func SetConfigInfo(n, c, p string) {
|
|
|
+ name = n
|
|
|
+ configType = c
|
|
|
+ path = p
|
|
|
+ Init()
|
|
|
}
|
|
|
|
|
|
func Load() error {
|