dao.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package archive
  2. import (
  3. "context"
  4. "go-common/app/admin/main/videoup/conf"
  5. "go-common/library/cache/redis"
  6. "go-common/library/database/hbase.v2"
  7. "go-common/library/database/sql"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. // Dao is redis dao.
  11. type Dao struct {
  12. c *conf.Config
  13. // db
  14. db *sql.DB
  15. rddb *sql.DB
  16. // redis
  17. redis *redis.Pool
  18. // hbase
  19. hbase *hbase.Client
  20. userCardURL string
  21. addQAVideoURL string
  22. clientW, clientR *bm.Client
  23. creativeDB *sql.DB
  24. }
  25. // New new a dao.
  26. func New(c *conf.Config) (d *Dao) {
  27. d = &Dao{
  28. c: c,
  29. db: sql.NewMySQL(c.DB.Archive),
  30. rddb: sql.NewMySQL(c.DB.ArchiveRead),
  31. redis: redis.NewPool(c.Redis.Track.Config),
  32. hbase: hbase.NewClient(&c.HBase.Config),
  33. userCardURL: c.Host.Account + "/api/member/getCardByMid",
  34. addQAVideoURL: c.Host.Task + "/vt/video/add",
  35. clientW: bm.NewClient(c.HTTPClient.Write),
  36. clientR: bm.NewClient(c.HTTPClient.Read),
  37. creativeDB: sql.NewMySQL(c.DB.Creative),
  38. }
  39. return d
  40. }
  41. // BeginTran begin transcation.
  42. func (d *Dao) BeginTran(c context.Context) (tx *sql.Tx, err error) {
  43. return d.db.Begin(c)
  44. }
  45. // Close close dao.
  46. func (d *Dao) Close() {
  47. if d.db != nil {
  48. d.db.Close()
  49. }
  50. if d.creativeDB != nil {
  51. d.creativeDB.Close()
  52. }
  53. d.redis.Close()
  54. }
  55. // Ping ping cpdb
  56. func (d *Dao) Ping(c context.Context) (err error) {
  57. return d.db.Ping(c)
  58. }