dao.go 977 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/admin/main/point/conf"
  5. "go-common/library/cache/memcache"
  6. "go-common/library/database/elastic"
  7. xsql "go-common/library/database/sql"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. const _searchBussinss = "vip_point_change_history"
  11. // Dao dao
  12. type Dao struct {
  13. c *conf.Config
  14. mc *memcache.Pool
  15. db *xsql.DB
  16. client *bm.Client
  17. es *elastic.Elastic
  18. }
  19. // New init mysql db
  20. func New(c *conf.Config) (dao *Dao) {
  21. dao = &Dao{
  22. c: c,
  23. mc: memcache.NewPool(c.Memcache),
  24. db: xsql.NewMySQL(c.MySQL),
  25. client: bm.NewClient(c.HTTPClient),
  26. // es
  27. es: elastic.NewElastic(nil),
  28. }
  29. return
  30. }
  31. // Close close the resource.
  32. func (dao *Dao) Close() {
  33. dao.mc.Close()
  34. dao.db.Close()
  35. }
  36. // Ping dao ping
  37. func (dao *Dao) Ping(c context.Context) error {
  38. return dao.pingMC(c)
  39. }
  40. // pingMc ping
  41. func (dao *Dao) pingMC(c context.Context) (err error) {
  42. conn := dao.mc.Get(c)
  43. defer conn.Close()
  44. return
  45. }