dao.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package dao
  2. import (
  3. "context"
  4. "net/http"
  5. "go-common/app/interface/main/player/conf"
  6. "go-common/library/database/sql"
  7. "go-common/library/log"
  8. xhttp "go-common/library/net/http/blademaster"
  9. "go-common/library/stat/prom"
  10. )
  11. // Dao dao.
  12. type Dao struct {
  13. // config
  14. c *conf.Config
  15. // mysql
  16. showDB *sql.DB
  17. // stmt
  18. paramStmt *sql.Stmt
  19. // client
  20. client *xhttp.Client
  21. vsClient *http.Client
  22. // API URL
  23. blockTimeURL string
  24. onlineCountURL string
  25. viewPointsURL string
  26. }
  27. // New return new dao.
  28. func New(c *conf.Config) (d *Dao) {
  29. d = &Dao{
  30. c: c,
  31. showDB: sql.NewMySQL(c.MySQL.Show),
  32. client: xhttp.NewClient(c.HTTPClient),
  33. vsClient: http.DefaultClient,
  34. }
  35. d.paramStmt = d.showDB.Prepared(_param)
  36. d.blockTimeURL = c.Host.AccCo + _blockTimeURI
  37. d.onlineCountURL = c.Host.APICo + _onlineCountURI
  38. d.viewPointsURL = c.Host.APICo + _viewPointsURI
  39. return
  40. }
  41. // Ping check service health
  42. func (d *Dao) Ping(c context.Context) (err error) {
  43. if err = d.showDB.Ping(c); err != nil {
  44. log.Error("d.show.Ping() err(%v)", err)
  45. }
  46. return
  47. }
  48. // PromError stat and log.
  49. func PromError(name string, format string, args ...interface{}) {
  50. prom.BusinessErrCount.Incr(name)
  51. log.Error(format, args...)
  52. }