dao.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package up
  2. import (
  3. "context"
  4. "go-common/app/admin/main/mcn/conf"
  5. "go-common/library/cache/memcache"
  6. xsql "go-common/library/database/sql"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. // Dao dao
  10. type Dao struct {
  11. c *conf.Config
  12. mc *memcache.Pool
  13. db *xsql.DB
  14. client *bm.Client
  15. arcTopURL string
  16. dataFansURL string
  17. dataFansBaseAttrURL string
  18. dataFansAreaURL string
  19. dataFansTypeURL string
  20. dataFansTagURL string
  21. }
  22. // New init mysql db
  23. func New(c *conf.Config) (dao *Dao) {
  24. dao = &Dao{
  25. c: c,
  26. mc: memcache.NewPool(c.Memcache),
  27. db: xsql.NewMySQL(c.MySQL),
  28. // http client
  29. client: bm.NewClient(c.HTTPClient),
  30. // url
  31. arcTopURL: c.Host.API + _arcTopURL,
  32. dataFansURL: c.Host.API + _dataFansURL,
  33. dataFansBaseAttrURL: c.Host.API + _dataFansBaseAttrURL,
  34. dataFansAreaURL: c.Host.API + _dataFansAreaURL,
  35. dataFansTypeURL: c.Host.API + _dataFansTypeURL,
  36. dataFansTagURL: c.Host.API + _dataFansTagURL,
  37. }
  38. return
  39. }
  40. // Close close the resource.
  41. func (d *Dao) Close() {
  42. d.mc.Close()
  43. d.db.Close()
  44. }
  45. // Ping dao ping
  46. func (d *Dao) Ping(c context.Context) error {
  47. // TODO: if you need use mc,redis, please add
  48. return d.db.Ping(c)
  49. }
  50. // BeginTran start tx .
  51. func (d *Dao) BeginTran(c context.Context) (tx *xsql.Tx, err error) {
  52. return d.db.Begin(c)
  53. }