init.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package main
  2. import (
  3. "github.com/spf13/viper"
  4. es "jygit.jydev.jianyu360.cn/data_processing/common_utils/elastic"
  5. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  6. )
  7. func InitConfig() (err error) {
  8. viper.SetConfigFile("config.toml") // 指定配置文件路径
  9. viper.SetConfigName("config") // 配置文件名称(无扩展名)
  10. viper.SetConfigType("toml") // 如果配置文件的名称中没有扩展名,则需要配置此项
  11. viper.AddConfigPath("./")
  12. viper.AddConfigPath("./conf/") // 还可以在工作目录中查找配置
  13. viper.AddConfigPath("../conf/") // 还可以在工作目录中查找配置
  14. err = viper.ReadInConfig() // 查找并读取配置文件
  15. if err != nil { // 处理读取配置文件的错误
  16. return
  17. }
  18. err = viper.Unmarshal(&GF)
  19. return err
  20. }
  21. func InitMgo() {
  22. Mgo = &mongodb.MongodbSim{
  23. MongodbAddr: GF.Mongo.Host,
  24. //MongodbAddr: "127.0.0.1:27083",
  25. Size: 10,
  26. DbName: GF.Mongo.DB,
  27. UserName: GF.Mongo.Username,
  28. Password: GF.Mongo.Password,
  29. Direct: GF.Mongo.Direct,
  30. }
  31. Mgo.InitPool()
  32. Esa = &es.Elastic{
  33. S_esurl: GF.Esa.URL,
  34. I_size: 5,
  35. Username: GF.Esa.Username,
  36. Password: GF.Esa.Password,
  37. }
  38. Esa.InitElasticSize()
  39. Esb = &es.Elastic{
  40. S_esurl: GF.Esb.URL,
  41. I_size: 5,
  42. Username: GF.Esb.Username,
  43. Password: GF.Esb.Password,
  44. }
  45. Esb.InitElasticSize()
  46. }