package main import ( "github.com/spf13/viper" es "jygit.jydev.jianyu360.cn/data_processing/common_utils/elastic" "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb" ) func InitConfig() (err error) { viper.SetConfigFile("config.toml") // 指定配置文件路径 viper.SetConfigName("config") // 配置文件名称(无扩展名) viper.SetConfigType("toml") // 如果配置文件的名称中没有扩展名,则需要配置此项 viper.AddConfigPath("./") viper.AddConfigPath("./conf/") // 还可以在工作目录中查找配置 viper.AddConfigPath("../conf/") // 还可以在工作目录中查找配置 err = viper.ReadInConfig() // 查找并读取配置文件 if err != nil { // 处理读取配置文件的错误 return } err = viper.Unmarshal(&GF) return err } func InitMgo() { Mgo = &mongodb.MongodbSim{ MongodbAddr: GF.Mongo.Host, //MongodbAddr: "127.0.0.1:27083", Size: 10, DbName: GF.Mongo.DB, UserName: GF.Mongo.Username, Password: GF.Mongo.Password, Direct: GF.Mongo.Direct, } Mgo.InitPool() Esa = &es.Elastic{ S_esurl: GF.Esa.URL, I_size: 5, Username: GF.Esa.Username, Password: GF.Esa.Password, } Esa.InitElasticSize() Esb = &es.Elastic{ S_esurl: GF.Esb.URL, I_size: 5, Username: GF.Esb.Username, Password: GF.Esb.Password, } Esb.InitElasticSize() }