server.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Package server generate by warden_gen
  2. package grpc
  3. import (
  4. "context"
  5. "fmt"
  6. pb "go-common/app/service/main/location/api"
  7. "go-common/app/service/main/location/model"
  8. "go-common/app/service/main/location/service"
  9. "go-common/library/net/rpc/warden"
  10. )
  11. // New Location warden rpc server
  12. func New(c *warden.ServerConfig, svr *service.Service) *warden.Server {
  13. ws := warden.NewServer(c)
  14. pb.RegisterLocationServer(ws.Server(), &server{svr})
  15. ws, err := ws.Start()
  16. if err != nil {
  17. panic(fmt.Sprintf("start warden server fail! %s", err))
  18. }
  19. return ws
  20. }
  21. type server struct {
  22. svr *service.Service
  23. }
  24. var _ pb.LocationServer = &server{}
  25. // Info get ip info.
  26. func (s *server) Info(c context.Context, arg *pb.InfoReq) (res *pb.InfoReply, err error) {
  27. var ipinfo *model.Info
  28. if ipinfo, err = s.svr.Info(c, arg.Addr); err != nil {
  29. return
  30. }
  31. res = &pb.InfoReply{
  32. Addr: ipinfo.Addr,
  33. Country: ipinfo.Country,
  34. Province: ipinfo.Province,
  35. City: ipinfo.City,
  36. Isp: ipinfo.ISP,
  37. Latitude: ipinfo.Latitude,
  38. Longitude: ipinfo.Longitude,
  39. ZoneId: ipinfo.ZoneID}
  40. return
  41. }