dao.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/job/main/passport/conf"
  5. "go-common/library/database/hbase.v2"
  6. "go-common/library/database/sql"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. // Dao struct info of Dao.
  11. type Dao struct {
  12. c *conf.Config
  13. logDB *sql.DB
  14. asoDB *sql.DB
  15. client *bm.Client
  16. gameClient *bm.Client
  17. loginLogHBase *hbase.Client
  18. pwdLogHBase *hbase.Client
  19. setTokenURI string
  20. delCacheURI string
  21. delGameCacheURI string
  22. }
  23. // New new a Dao and return.
  24. func New(c *conf.Config) (d *Dao) {
  25. d = &Dao{
  26. c: c,
  27. logDB: sql.NewMySQL(c.DB.Log),
  28. asoDB: sql.NewMySQL(c.DB.ASO),
  29. client: bm.NewClient(c.HTTPClient),
  30. gameClient: bm.NewClient(c.Game.Client),
  31. loginLogHBase: hbase.NewClient(c.HBase.LoginLog.Config),
  32. pwdLogHBase: hbase.NewClient(c.HBase.PwdLog.Config),
  33. setTokenURI: c.URI.SetToken,
  34. delCacheURI: c.URI.DelCache,
  35. delGameCacheURI: c.Game.DelCacheURI,
  36. }
  37. return d
  38. }
  39. // Ping ping check dao health.
  40. func (d *Dao) Ping(c context.Context) (err error) {
  41. if err = d.logDB.Ping(c); err != nil {
  42. log.Info("dao.logDB.Ping() error(%v)", err)
  43. }
  44. return
  45. }
  46. // Close close dao.
  47. func (d *Dao) Close() (err error) {
  48. if d.logDB != nil {
  49. d.logDB.Close()
  50. }
  51. if d.loginLogHBase != nil {
  52. d.loginLogHBase.Close()
  53. }
  54. if d.pwdLogHBase != nil {
  55. d.pwdLogHBase.Close()
  56. }
  57. return
  58. }