dao.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/interface/live/app-room/conf"
  5. userextApi "go-common/app/service/live/userext/api/liverpc"
  6. xUserEx "go-common/app/service/live/xuserex/api/grpc/v1"
  7. "go-common/library/cache"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. )
  11. const (
  12. _payCenterWalletURL = "/wallet-int/wallet/getUserWalletInfo"
  13. _liveWalletURL = "/x/internal/livewallet/wallet/getAll"
  14. )
  15. // Dao dao
  16. type Dao struct {
  17. c *conf.Config
  18. payCenterWalletURL string
  19. payCenterClient *bm.Client
  20. liveWalletURL string
  21. liveWalletClient *bm.Client
  22. UserExtAPI *userextApi.Client
  23. giftCache *cache.Cache
  24. XuserexAPI *xUserEx.Client
  25. }
  26. // New init mysql db
  27. func New(c *conf.Config) (dao *Dao) {
  28. dao = &Dao{
  29. c: c,
  30. payCenterWalletURL: c.Host.PayCenter + _payCenterWalletURL,
  31. payCenterClient: bm.NewClient(c.HTTPClient.PayCenter),
  32. liveWalletURL: c.Host.LiveRpc + _liveWalletURL,
  33. liveWalletClient: bm.NewClient(c.HTTPClient.LiveRpc),
  34. giftCache: cache.New(1, 1024),
  35. }
  36. xUserexApi, err := xUserEx.NewClient(c.Warden)
  37. if err != nil {
  38. log.Error("init xuserex error(%v)", err)
  39. }
  40. dao.XuserexAPI = xUserexApi
  41. InitAPI(dao)
  42. return
  43. }
  44. // Close close the resource.
  45. func (d *Dao) Close() {
  46. }
  47. // Ping dao ping
  48. func (d *Dao) Ping(c context.Context) error {
  49. // TODO: if you need use mc,redis, please add
  50. // check
  51. return nil
  52. }