dao.go 907 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package dao
  2. import (
  3. "context"
  4. "net/http"
  5. "time"
  6. "go-common/app/job/main/answer/conf"
  7. "go-common/library/database/sql"
  8. xhttp "go-common/library/net/http/blademaster"
  9. )
  10. const (
  11. _bfsTimeout = 5 * time.Second
  12. _beFormal = "/api/internal/member/beFormal"
  13. )
  14. // Dao event dao def.
  15. type Dao struct {
  16. c *conf.Config
  17. db *sql.DB
  18. client *http.Client
  19. xclient *xhttp.Client
  20. beFormal string
  21. }
  22. // New create instance of dao and return.
  23. func New(c *conf.Config) (d *Dao) {
  24. d = &Dao{
  25. c: c,
  26. db: sql.NewMySQL(c.Mysql),
  27. client: &http.Client{
  28. Timeout: _bfsTimeout,
  29. },
  30. xclient: xhttp.NewClient(c.HTTPClient),
  31. beFormal: c.Properties.AccountIntranetURI + _beFormal,
  32. }
  33. return
  34. }
  35. // Ping check db health.
  36. func (d *Dao) Ping(c context.Context) (err error) {
  37. return d.db.Ping(c)
  38. }
  39. // Close close all db connections.
  40. func (d *Dao) Close() {
  41. if d.db != nil {
  42. d.db.Close()
  43. }
  44. }