dao.go 686 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package ads
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/service/main/resource/conf"
  6. "go-common/library/cache/redis"
  7. xsql "go-common/library/database/sql"
  8. )
  9. // Dao is resource dao.
  10. type Dao struct {
  11. db *xsql.DB
  12. c *conf.Config
  13. // redis
  14. redis *redis.Pool
  15. expire int32
  16. }
  17. // New init mysql db
  18. func New(c *conf.Config) (d *Dao) {
  19. d = &Dao{
  20. c: c,
  21. db: xsql.NewMySQL(c.DB.Ads),
  22. redis: redis.NewPool(c.Redis.Ads.Config),
  23. expire: int32(time.Duration(c.Redis.Ads.Expire) / time.Second),
  24. }
  25. return
  26. }
  27. // Close close the resource.
  28. func (d *Dao) Close() {
  29. d.db.Close()
  30. }
  31. // Ping check dao health.
  32. func (d *Dao) Ping(c context.Context) error {
  33. return d.db.Ping(c)
  34. }