db.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. 初始数据库应用
  3. */
  4. package init
  5. import (
  6. "app.yhyue.com/moapp/jybase/esv1"
  7. "app.yhyue.com/moapp/jybase/mongodb"
  8. "app.yhyue.com/moapp/jybase/mysql"
  9. "app.yhyue.com/moapp/jybase/redis"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. "jyBXBase/entity"
  12. "strings"
  13. )
  14. var (
  15. MainMysql *mysql.Mysql
  16. BaseServiceMysql *mysql.Mysql
  17. Mgo mongodb.MongodbSim
  18. MgoEnt mongodb.MongodbSim
  19. MgoBidding mongodb.MongodbSim
  20. )
  21. //
  22. func MongoDBInit(em *entity.Mongo) {
  23. //初始化 mongodb
  24. if em.Main.Address != "" {
  25. logx.Info("--初始化 mongodb--")
  26. Mgo = mongodb.MongodbSim{
  27. MongodbAddr: em.Main.Address,
  28. Size: em.Main.Size,
  29. DbName: em.Main.DbName,
  30. }
  31. Mgo.InitPool()
  32. }
  33. //
  34. if em.Bidding.Address != "" {
  35. logx.Info("--初始化 mongodb bidding--")
  36. MgoBidding = mongodb.MongodbSim{
  37. MongodbAddr: em.Bidding.Address,
  38. Size: em.Bidding.Size,
  39. DbName: em.Bidding.DbName,
  40. UserName: em.Bidding.UserName,
  41. Password: em.Bidding.Password,
  42. }
  43. MgoBidding.InitPool()
  44. }
  45. if em.Ent.Address != "" {
  46. logx.Info("--初始化 mongodb ent--")
  47. MgoEnt = mongodb.MongodbSim{
  48. MongodbAddr: em.Ent.Address,
  49. Size: em.Ent.Size,
  50. DbName: em.Ent.DbName,
  51. UserName: em.Ent.UserName,
  52. Password: em.Ent.Password,
  53. }
  54. MgoEnt.InitPool()
  55. }
  56. }
  57. //
  58. func MysqlInit(em *entity.Mysql) {
  59. //初始化 mysql-main
  60. if em.Main.Address != "" {
  61. logx.Info("--初始化 main mysql--")
  62. MainMysql = &mysql.Mysql{
  63. Address: em.Main.Address,
  64. UserName: em.Main.UserName,
  65. PassWord: em.Main.Password,
  66. DBName: em.Main.DbName,
  67. MaxOpenConns: em.Main.MaxOpenConns,
  68. MaxIdleConns: em.Main.MaxIdleConns,
  69. }
  70. MainMysql.Init()
  71. }
  72. //初始化 mysql-BaseService
  73. if em.BaseService.Address != "" {
  74. logx.Info("--初始化 推送 mysql--")
  75. BaseServiceMysql = &mysql.Mysql{
  76. Address: em.BaseService.Address,
  77. UserName: em.BaseService.UserName,
  78. PassWord: em.BaseService.Password,
  79. DBName: em.BaseService.DbName,
  80. MaxOpenConns: em.BaseService.MaxOpenConns,
  81. MaxIdleConns: em.BaseService.MaxIdleConns,
  82. }
  83. BaseServiceMysql.Init()
  84. }
  85. }
  86. //
  87. func RedisInit(rm *entity.RedisStuct) {
  88. //初始化 redis
  89. if len(rm.Addr) > 0 {
  90. logx.Info("--初始化 redis--")
  91. redis.InitRedisBySize(strings.Join(rm.Addr, ","), 100, 30, 300)
  92. }
  93. }
  94. //
  95. func EsInit(es *entity.EsStruct) {
  96. //初始化 elasticsearch
  97. if es.Addr != "" {
  98. logx.Info("--初始化 elasticsearch--")
  99. elastic.InitElasticSize(es.Addr, es.Size)
  100. }
  101. }