dao.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package location
  2. import (
  3. "context"
  4. "strconv"
  5. "go-common/app/interface/main/app-intl/conf"
  6. locmdl "go-common/app/service/main/location/model"
  7. locrpc "go-common/app/service/main/location/rpc/client"
  8. "go-common/library/log"
  9. )
  10. // Dao is location dao.
  11. type Dao struct {
  12. // rpc
  13. locRPC *locrpc.Service
  14. }
  15. // New new a location dao.
  16. func New(c *conf.Config) (d *Dao) {
  17. d = &Dao{
  18. // rpc
  19. locRPC: locrpc.New(c.LocationRPC),
  20. }
  21. return
  22. }
  23. func (d *Dao) Info(c context.Context, ipaddr string) (info *locmdl.Info, err error) {
  24. if info, err = d.locRPC.Info(c, &locmdl.ArgIP{IP: ipaddr}); err != nil {
  25. log.Error("%v", err)
  26. }
  27. return
  28. }
  29. func (d *Dao) AuthPIDs(c context.Context, pids, ipaddr string) (res map[string]*locmdl.Auth, err error) {
  30. var auths map[int64]*locmdl.Auth
  31. if auths, err = d.locRPC.AuthPIDs(c, &locmdl.ArgPids{Pids: pids, IP: ipaddr}); err != nil {
  32. log.Error("%v", err)
  33. return
  34. }
  35. res = make(map[string]*locmdl.Auth)
  36. for pid, auth := range auths {
  37. p := strconv.FormatInt(pid, 10)
  38. res[p] = auth
  39. }
  40. return
  41. }
  42. func (d *Dao) Archive(c context.Context, aid, mid int64, ipaddr, cndip string) (auth *locmdl.Auth, err error) {
  43. if auth, err = d.locRPC.Archive2(c, &locmdl.Archive{Aid: aid, Mid: mid, IP: ipaddr, CIP: cndip}); err != nil {
  44. log.Error("%v", err)
  45. }
  46. return
  47. }