dao.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package weeklyhonor
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/job/main/creative/conf"
  6. arcrpc "go-common/app/service/main/archive/api/gorpc"
  7. upgrpc "go-common/app/service/main/up/api/v1"
  8. "go-common/library/database/hbase.v2"
  9. "go-common/library/database/sql"
  10. binfoc "go-common/library/log/infoc"
  11. bm "go-common/library/net/http/blademaster"
  12. )
  13. // Dao is creative dao.
  14. type Dao struct {
  15. // config
  16. c *conf.Config
  17. // db
  18. db *sql.DB
  19. // httpClient
  20. httpClient *bm.Client
  21. // hbase
  22. hbase *hbase.Client
  23. hbaseTimeOut time.Duration
  24. // rpc
  25. arc *arcrpc.Service2
  26. infoc *binfoc.Infoc
  27. // grpc
  28. upClient upgrpc.UpClient
  29. }
  30. // New init api url
  31. func New(c *conf.Config) (d *Dao) {
  32. d = &Dao{
  33. c: c,
  34. db: sql.NewMySQL(c.DB.Creative),
  35. httpClient: bm.NewClient(c.HTTPClient.Normal),
  36. // hbase
  37. hbase: hbase.NewClient(c.HBaseOld.Config),
  38. hbaseTimeOut: time.Duration(time.Millisecond * 200),
  39. arc: arcrpc.New2(c.ArchiveRPC),
  40. infoc: binfoc.New(c.WeeklyHonorInfoc),
  41. }
  42. var err error
  43. d.upClient, err = upgrpc.NewClient(c.UpGRPCClient)
  44. if err != nil {
  45. panic(err)
  46. }
  47. return
  48. }
  49. // Ping creativeDb
  50. func (d *Dao) Ping(c context.Context) (err error) {
  51. return d.pingMySQL(c)
  52. }
  53. // Close creativeDb
  54. func (d *Dao) Close() (err error) {
  55. _ = d.infoc.Close()
  56. return d.db.Close()
  57. }