dao.go 1020 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package dao
  2. import (
  3. "context"
  4. livecaptchaApi "go-common/app/service/live/captcha/api/liverpc"
  5. "go-common/app/service/live/xcaptcha/conf"
  6. "go-common/library/cache/redis"
  7. "go-common/library/net/rpc/liverpc"
  8. "go-common/library/queue/databus"
  9. )
  10. // Dao dao
  11. type Dao struct {
  12. c *conf.Config
  13. redis *redis.Pool
  14. geeClient *GeeClient
  15. liveCaptcha *livecaptchaApi.Client
  16. captchaAnti *databus.Databus
  17. }
  18. // New init mysql db
  19. func New(c *conf.Config) (dao *Dao) {
  20. dao = &Dao{
  21. c: c,
  22. redis: redis.NewPool(c.Redis),
  23. geeClient: NewGeeClient(c.GeeTest),
  24. liveCaptcha: livecaptchaApi.New(getConf("captcha")),
  25. captchaAnti: databus.New(c.DataBus.CaptchaAnti),
  26. }
  27. return
  28. }
  29. // getConf get liveRpc conf
  30. func getConf(appName string) *liverpc.ClientConfig {
  31. c := conf.Conf.LiveRpc
  32. if c != nil {
  33. return c[appName]
  34. }
  35. return nil
  36. }
  37. // Close close the resource.
  38. func (d *Dao) Close() {
  39. d.redis.Close()
  40. }
  41. // Ping dao ping
  42. func (d *Dao) Ping(c context.Context) error {
  43. return nil
  44. }