dao.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/admin/main/coupon/conf"
  5. seasongrpc "go-common/app/service/openplatform/pgc-season/api/grpc/season/v1"
  6. "go-common/library/cache/memcache"
  7. "go-common/library/database/elastic"
  8. xsql "go-common/library/database/sql"
  9. "go-common/library/log"
  10. bm "go-common/library/net/http/blademaster"
  11. )
  12. // Dao dao
  13. type Dao struct {
  14. c *conf.Config
  15. db *xsql.DB
  16. es *elastic.Elastic
  17. mc *memcache.Pool
  18. // grpc
  19. rpcClient seasongrpc.SeasonClient
  20. client *bm.Client
  21. }
  22. // New init mysql db
  23. func New(c *conf.Config) (dao *Dao) {
  24. dao = &Dao{
  25. c: c,
  26. db: xsql.NewMySQL(c.MySQL),
  27. // es
  28. es: elastic.NewElastic(nil),
  29. mc: memcache.NewPool(c.Memcache.Config),
  30. client: bm.NewClient(c.HTTPClient),
  31. }
  32. var err error
  33. if dao.rpcClient, err = seasongrpc.NewClient(c.PGCRPC); err != nil {
  34. log.Error("seasongrpc NewClientt error(%v)", err)
  35. }
  36. return
  37. }
  38. // Close close the resource.
  39. func (dao *Dao) Close() {
  40. dao.db.Close()
  41. }
  42. // Ping dao ping
  43. func (dao *Dao) Ping(c context.Context) error {
  44. return dao.db.Ping(c)
  45. }