dao.go 889 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package esports
  2. import (
  3. "context"
  4. "go-common/app/job/main/web-goblin/conf"
  5. "go-common/library/database/sql"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. const _pushURL = "/x/internal/push-strategy/task/add"
  9. // Dao dao
  10. type Dao struct {
  11. c *conf.Config
  12. // http client
  13. http *bm.Client
  14. messageHTTPClient *bm.Client
  15. // push service URL
  16. pushURL string
  17. // db
  18. db *sql.DB
  19. }
  20. // New init mysql db
  21. func New(c *conf.Config) (dao *Dao) {
  22. dao = &Dao{
  23. c: c,
  24. http: bm.NewClient(c.HTTPClient),
  25. messageHTTPClient: bm.NewClient(c.MessageHTTPClient),
  26. db: sql.NewMySQL(c.DB.Esports),
  27. pushURL: c.Host.API + _pushURL,
  28. }
  29. return
  30. }
  31. // Close close the resource.
  32. func (d *Dao) Close() {
  33. }
  34. // Ping ping dao
  35. func (d *Dao) Ping(c context.Context) (err error) {
  36. if err = d.db.Ping(c); err != nil {
  37. return
  38. }
  39. return
  40. }