dao.go 847 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package location
  2. import (
  3. "context"
  4. "strconv"
  5. "go-common/app/interface/main/app-channel/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) AuthPIDs(c context.Context, pids, ipaddr string) (res map[string]*locmdl.Auth, err error) {
  24. var auths map[int64]*locmdl.Auth
  25. if auths, err = d.locRPC.AuthPIDs(c, &locmdl.ArgPids{Pids: pids, IP: ipaddr}); err != nil {
  26. log.Error("%v", err)
  27. return
  28. }
  29. res = make(map[string]*locmdl.Auth)
  30. for pid, auth := range auths {
  31. p := strconv.FormatInt(pid, 10)
  32. res[p] = auth
  33. }
  34. return
  35. }