dao.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/job/main/growup/conf"
  5. "go-common/library/database/hbase.v2"
  6. "go-common/library/database/sql"
  7. "go-common/library/log"
  8. xhttp "go-common/library/net/http/blademaster"
  9. )
  10. // Dao dao
  11. type Dao struct {
  12. c *conf.Config
  13. db *sql.DB
  14. rddb *sql.DB
  15. archiveURL string
  16. typeURL string
  17. breachURL string
  18. forbidURL string
  19. dismissURL string
  20. passURL string
  21. avLotteryURL string
  22. avVoteURL string
  23. client *xhttp.Client
  24. // hbase
  25. hbase *hbase.Client
  26. }
  27. // New fn
  28. func New(c *conf.Config) (d *Dao) {
  29. log.Info("dao start")
  30. d = &Dao{
  31. c: c,
  32. db: sql.NewMySQL(c.Mysql.Growup),
  33. rddb: sql.NewMySQL(c.Mysql.Allowance),
  34. client: xhttp.NewClient(c.HTTPClient),
  35. archiveURL: c.Host.Archive + "/manager/search",
  36. typeURL: c.Host.VideoType + "/videoup/types",
  37. breachURL: c.Host.Profit + "/allowance/api/x/admin/growup/auto/archive/breach",
  38. forbidURL: c.Host.Profit + "/allowance/api/x/admin/growup/auto/up/forbid",
  39. dismissURL: c.Host.Profit + "/allowance/api/x/admin/growup/auto/up/dismiss",
  40. passURL: c.Host.Profit + "/allowance/api/x/admin/growup/up/pass",
  41. avLotteryURL: c.Host.VC + "/lottery_svr/v0/lottery_svr/export_rids",
  42. avVoteURL: c.Host.API + "/x/internal/creative/archive/vote",
  43. // hbase
  44. hbase: hbase.NewClient(c.HBase.Config),
  45. }
  46. log.Info("data init end")
  47. //d.db.State = prom.LibClient
  48. return
  49. }
  50. // Ping ping health.
  51. func (d *Dao) Ping(c context.Context) (err error) {
  52. return d.db.Ping(c)
  53. }
  54. // Close close connections of mc, redis, db.
  55. func (d *Dao) Close() {
  56. if d.db != nil {
  57. d.db.Close()
  58. }
  59. }
  60. // BeginTran begin transcation
  61. func (d *Dao) BeginTran(c context.Context) (tx *sql.Tx, err error) {
  62. return d.db.Begin(c)
  63. }