display.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package display
  2. import (
  3. "context"
  4. "go-common/library/net/metadata"
  5. "strconv"
  6. "time"
  7. locmdl "go-common/app/service/main/location/model"
  8. "go-common/library/log"
  9. xip "go-common/library/net/ip"
  10. )
  11. // DisplayID is display id .
  12. func (s *Service) DisplayID(c context.Context, mid int64, buvid string, now time.Time) (id string) {
  13. if mid == 0 {
  14. id = buvid + "-" + strconv.FormatInt(now.Unix(), 10)
  15. } else {
  16. id = strconv.FormatInt(mid, 10) + "-" + strconv.FormatInt(now.Unix(), 10)
  17. }
  18. return
  19. }
  20. // Zone is zone id and district info .
  21. func (s *Service) Zone(c context.Context, now time.Time) (zone *xip.Zone) {
  22. var (
  23. info *locmdl.Info
  24. err error
  25. )
  26. zone = &xip.Zone{}
  27. if info, err = s.loc.Info(c, metadata.String(c, metadata.RemoteIP)); err != nil || info == nil {
  28. log.Error("error %v or info is nil", err)
  29. return
  30. }
  31. zone.ID = info.ZoneID
  32. zone.Addr = info.Addr
  33. zone.ISP = info.ISP
  34. zone.Country = info.Country
  35. zone.Province = info.Province
  36. zone.City = info.City
  37. zone.Latitude = info.Latitude
  38. zone.Longitude = info.Longitude
  39. zone.CountryCode = info.CountryCode
  40. return
  41. }