db.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package db
  2. import (
  3. "log"
  4. "strings"
  5. "app.yhyue.com/moapp/jybase/mongodb"
  6. "app.yhyue.com/moapp/jybase/redis"
  7. "app.yhyue.com/moapp/jybase/mysql"
  8. "bp.jydev.jianyu360.cn/BaseService/userCenter/entity"
  9. )
  10. func init() {
  11. entity.Mysql = &mysql.Mysql{
  12. Address: entity.ConfigJson.Mysql.Address,
  13. UserName: entity.ConfigJson.Mysql.UserName,
  14. PassWord: entity.ConfigJson.Mysql.PassWord,
  15. DBName: entity.ConfigJson.Mysql.DbName,
  16. MaxOpenConns: entity.ConfigJson.Mysql.MaxOpenConns,
  17. MaxIdleConns: entity.ConfigJson.Mysql.MaxIdleConns,
  18. }
  19. log.Println("初始化 mysql")
  20. entity.Mysql.Init()
  21. entity.BaseMysql = &mysql.Mysql{
  22. Address: entity.ConfigJson.BaseMysql.Address,
  23. UserName: entity.ConfigJson.BaseMysql.UserName,
  24. PassWord: entity.ConfigJson.BaseMysql.PassWord,
  25. DBName: entity.ConfigJson.BaseMysql.DbName,
  26. MaxOpenConns: entity.ConfigJson.BaseMysql.MaxOpenConns,
  27. MaxIdleConns: entity.ConfigJson.BaseMysql.MaxIdleConns,
  28. }
  29. log.Println("初始化 base mysql")
  30. entity.BaseMysql.Init()
  31. log.Println("初始化 redis")
  32. redis.InitRedisBySize(strings.Join(entity.ConfigJson.RedisAddrees, ","), 100, 30, 300)
  33. //初始化 mongodb
  34. if entity.ConfigJson.Mongo.Main.Address != "" {
  35. log.Println("初始化 mongo main")
  36. entity.Mgo = mongodb.MongodbSim{
  37. MongodbAddr: entity.ConfigJson.Mongo.Main.Address,
  38. Size: entity.ConfigJson.Mongo.Main.Size,
  39. DbName: entity.ConfigJson.Mongo.Main.DbName,
  40. }
  41. entity.Mgo.InitPool()
  42. }
  43. //用户角色功能初始化
  44. entity.UserRolePowerInit(entity.ConfigJson.UserRolePower)
  45. log.Println("初始化 mysql")
  46. }