dao.go 827 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package monitor
  2. import (
  3. "context"
  4. "go-common/app/job/main/aegis/conf"
  5. "go-common/library/cache/redis"
  6. xsql "go-common/library/database/sql"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. type Dao struct {
  10. c *conf.Config
  11. redis *redis.Pool
  12. db *xsql.DB
  13. http *bm.Client
  14. URLArcAddit string
  15. }
  16. // New init mysql db
  17. func New(c *conf.Config) (dao *Dao) {
  18. dao = &Dao{
  19. c: c,
  20. redis: redis.NewPool(c.Redis),
  21. db: xsql.NewMySQL(c.MySQL.Fast),
  22. http: bm.NewClient(c.HTTP.Fast),
  23. URLArcAddit: c.Host.Videoup + _arcAdditURL,
  24. }
  25. return
  26. }
  27. // Close close the resource.
  28. func (d *Dao) Close() {
  29. d.redis.Close()
  30. d.db.Close()
  31. }
  32. // Ping dao ping
  33. func (d *Dao) Ping(c context.Context) error {
  34. // TODO: if you need use mc,redis, please add
  35. return d.db.Ping(c)
  36. }