dao.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package resource
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-feed/conf"
  5. "go-common/app/service/main/resource/model"
  6. rscrpc "go-common/app/service/main/resource/rpc/client"
  7. "go-common/library/log"
  8. "go-common/library/net/metadata"
  9. "github.com/pkg/errors"
  10. )
  11. type Dao struct {
  12. c *conf.Config
  13. // rpc
  14. rscRPC *rscrpc.Service
  15. }
  16. func New(c *conf.Config) (d *Dao) {
  17. d = &Dao{
  18. c: c,
  19. // rpc
  20. rscRPC: rscrpc.New(c.ResourceRPC),
  21. }
  22. return
  23. }
  24. func (d *Dao) Banner(c context.Context, plat int8, build int, mid int64, resIDs, channel, buvid, network, mobiApp, device string, isAd bool, openEvent, adExtra, hash string) (res map[int][]*model.Banner, version string, err error) {
  25. ip := metadata.String(c, metadata.RemoteIP)
  26. arg := &model.ArgBanner{Plat: plat, ResIDs: resIDs, Build: build, MID: mid, Channel: channel, IP: ip, Buvid: buvid, Network: network, MobiApp: mobiApp, Device: device, IsAd: isAd, OpenEvent: openEvent, AdExtra: adExtra, Version: hash}
  27. bs, err := d.rscRPC.Banners(c, arg)
  28. if err != nil {
  29. err = errors.Wrapf(err, "%v", arg)
  30. return
  31. }
  32. if bs != nil {
  33. res = bs.Banner
  34. version = bs.Version
  35. }
  36. return
  37. }
  38. // AbTest resource abtest
  39. func (d *Dao) AbTest(ctx context.Context, groups string) (res map[string]*model.AbTest, err error) {
  40. arg := &model.ArgAbTest{
  41. Groups: groups,
  42. }
  43. if res, err = d.rscRPC.AbTest(ctx, arg); err != nil {
  44. log.Error("resource d.resRpc.AbTest error(%v)", err)
  45. return
  46. }
  47. return
  48. }