dao.go 942 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package web
  2. import (
  3. "context"
  4. "go-common/app/job/main/web-goblin/conf"
  5. "go-common/library/database/elastic"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/stat/prom"
  9. )
  10. const _broadURL = "/x/internal/broadcast/push/all"
  11. // Dao dao
  12. type Dao struct {
  13. c *conf.Config
  14. // http client
  15. http *bm.Client
  16. // broadcast URL
  17. broadcastURL string
  18. ela *elastic.Elastic
  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. broadcastURL: c.Host.API + _broadURL,
  26. ela: elastic.NewElastic(nil),
  27. }
  28. return
  29. }
  30. // Close close the resource.
  31. func (d *Dao) Close() {
  32. }
  33. // Ping dao ping
  34. func (d *Dao) Ping(c context.Context) error {
  35. return nil
  36. }
  37. // PromError stat and log.
  38. func PromError(name string, format string, args ...interface{}) {
  39. prom.BusinessErrCount.Incr(name)
  40. log.Error(format, args...)
  41. }