From 5894e0a9941e146c8b49c8105e1ecff6fac04c79 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 5 May 2021 10:37:23 +0100 Subject: [PATCH] update the geocoding api (#93) --- geocoding/handler/handler.go | 31 +- geocoding/handler/handler_test.go | 69 ++-- geocoding/proto/geocoding.pb.go | 455 +++++++++++++++++++++----- geocoding/proto/geocoding.pb.micro.go | 33 +- geocoding/proto/geocoding.proto | 50 ++- 5 files changed, 482 insertions(+), 156 deletions(-) diff --git a/geocoding/handler/handler.go b/geocoding/handler/handler.go index d4514ed..7397b60 100644 --- a/geocoding/handler/handler.go +++ b/geocoding/handler/handler.go @@ -22,10 +22,9 @@ type Geocoding struct { Maps *maps.Client } -// Geocode an address -func (g *Geocoding) Geocode(ctx context.Context, req *pb.Address, rsp *pb.Address) error { +func (g *Geocoding) Lookup(ctx context.Context, req *pb.LookupRequest, rsp *pb.LookupResponse) error { // query google maps - results, err := g.Maps.Geocode(ctx, &maps.GeocodingRequest{Address: toString(req)}) + results, err := g.Maps.Geocode(ctx, &maps.GeocodingRequest{Address: req.Address}) if err != nil { logger.Errorf("Error geocoding: %v", err) return ErrDownstream @@ -34,24 +33,28 @@ func (g *Geocoding) Geocode(ctx context.Context, req *pb.Address, rsp *pb.Addres return ErrNoResults } + rsp.Address = new(pb.Address) + rsp.Location = new(pb.Location) + // return the result - serializeResult(results[0], rsp) + serializeResult(results[0], rsp.Address, rsp.Location) + return nil } // Reverse geocode an address -func (g *Geocoding) Reverse(ctx context.Context, req *pb.Coordinates, rsp *pb.Address) error { +func (g *Geocoding) Reverse(ctx context.Context, req *pb.ReverseRequest, rsp *pb.ReverseResponse) error { // validate the request - if req.Latitude == nil { + if req.Latitude == 0.0 { return ErrMissingLatitude } - if req.Longitude == nil { + if req.Longitude == 0.0 { return ErrMissingLongitude } // query google maps results, err := g.Maps.ReverseGeocode(ctx, &maps.GeocodingRequest{ - LatLng: &maps.LatLng{Lat: req.Latitude.Value, Lng: req.Longitude.Value}, + LatLng: &maps.LatLng{Lat: req.Latitude, Lng: req.Longitude}, }) if err != nil { logger.Errorf("Error geocoding: %v", err) @@ -61,8 +64,11 @@ func (g *Geocoding) Reverse(ctx context.Context, req *pb.Coordinates, rsp *pb.Ad return ErrNoResults } + rsp.Address = new(pb.Address) + rsp.Location = new(pb.Location) + // return the result - serializeResult(results[0], rsp) + serializeResult(results[0], rsp.Address, rsp.Location) return nil } @@ -77,8 +83,9 @@ func toString(a *pb.Address) string { return strings.Join(comps, ", ") } -func serializeResult(r maps.GeocodingResult, a *pb.Address) { +func serializeResult(r maps.GeocodingResult, a *pb.Address, l *pb.Location) { var street, number string + for _, c := range r.AddressComponents { for _, t := range c.Types { switch t { @@ -99,6 +106,6 @@ func serializeResult(r maps.GeocodingResult, a *pb.Address) { } a.LineOne = strings.Join([]string{number, street}, " ") - a.Latitude = r.Geometry.Location.Lat - a.Longitude = r.Geometry.Location.Lng + l.Latitude = r.Geometry.Location.Lat + l.Longitude = r.Geometry.Location.Lng } diff --git a/geocoding/handler/handler_test.go b/geocoding/handler/handler_test.go index b36fe66..c06ca33 100644 --- a/geocoding/handler/handler_test.go +++ b/geocoding/handler/handler_test.go @@ -9,7 +9,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "google.golang.org/protobuf/types/known/wrapperspb" "googlemaps.github.io/maps" "github.com/micro/services/geocoding/handler" @@ -148,17 +147,31 @@ func TestGeocoding(t *testing.T) { } h := &handler.Geocoding{Maps: m} - var rsp pb.Address - err = h.Geocode(context.TODO(), tc.Address, &rsp) + var rsp pb.LookupResponse + address := tc.Address.LineOne + if len(tc.Address.LineTwo) > 0 { + address = fmt.Sprintf("%s, %s", address, tc.Address.LineTwo) + } + if len(tc.Address.Postcode) > 0 { + address = fmt.Sprintf("%s, %s", address, tc.Address.Postcode) + } + if len(tc.Address.Country) > 0 { + address = fmt.Sprintf("%s, %s", address, tc.Address.Country) + } + err = h.Lookup(context.TODO(), &pb.LookupRequest{ + Address: address, + Postcode: tc.Address.Postcode, + Country: tc.Address.Country, + }, &rsp) assert.Equal(t, tc.MapQuery, query) assert.Equal(t, tc.Error, err) if tc.Result != nil { - assert.Equal(t, tc.Result.LineOne, rsp.LineOne) - assert.Equal(t, tc.Result.LineTwo, rsp.LineTwo) - assert.Equal(t, tc.Result.City, rsp.City) - assert.Equal(t, tc.Result.Country, rsp.Country) - assert.Equal(t, tc.Result.Postcode, rsp.Postcode) + assert.Equal(t, tc.Result.LineOne, rsp.Address.LineOne) + assert.Equal(t, tc.Result.LineTwo, rsp.Address.LineTwo) + assert.Equal(t, tc.Result.City, rsp.Address.City) + assert.Equal(t, tc.Result.Country, rsp.Address.Country) + assert.Equal(t, tc.Result.Postcode, rsp.Address.Postcode) } }) } @@ -171,34 +184,34 @@ func TestReverseGeocoding(t *testing.T) { ResponseBody string ResponseCode int Error error - Latitude *wrapperspb.DoubleValue - Longitude *wrapperspb.DoubleValue + Latitude float64 + Longitude float64 Result *pb.Address }{ { Name: "Missing longitude", - Latitude: &wrapperspb.DoubleValue{Value: 51.522214}, + Latitude: 51.522214, Error: handler.ErrMissingLongitude, }, { Name: "Missing latitude", - Longitude: &wrapperspb.DoubleValue{Value: -0.113565}, + Longitude: -0.113565, Error: handler.ErrMissingLatitude, }, { Name: "Invalid address", ResponseBody: noResultsReponse, ResponseCode: http.StatusOK, - Latitude: &wrapperspb.DoubleValue{Value: 999.999999}, - Longitude: &wrapperspb.DoubleValue{Value: 999.999999}, + Latitude: 999.999999, + Longitude: 999.999999, Error: handler.ErrNoResults, }, { Name: "Valid address", ResponseBody: validReponse, ResponseCode: http.StatusOK, - Latitude: &wrapperspb.DoubleValue{Value: 51.522214}, - Longitude: &wrapperspb.DoubleValue{Value: -0.113565}, + Latitude: 51.522214, + Longitude: -0.113565, Result: &pb.Address{ LineOne: "160 Grays Inn Road", LineTwo: "Holborn", @@ -208,8 +221,8 @@ func TestReverseGeocoding(t *testing.T) { }, { Name: "Maps error", - Latitude: &wrapperspb.DoubleValue{Value: 51.522214}, - Longitude: &wrapperspb.DoubleValue{Value: -0.113565}, + Latitude: 51.522214, + Longitude: -0.113565, ResponseCode: http.StatusInternalServerError, Error: handler.ErrDownstream, ResponseBody: "{}", @@ -237,23 +250,23 @@ func TestReverseGeocoding(t *testing.T) { } h := &handler.Geocoding{Maps: m} - var rsp pb.Address - err = h.Reverse(context.TODO(), &pb.Coordinates{ + var rsp pb.ReverseResponse + err = h.Reverse(context.TODO(), &pb.ReverseRequest{ Latitude: tc.Latitude, Longitude: tc.Longitude, }, &rsp) assert.Equal(t, tc.Error, err) - if tc.Latitude != nil && tc.Longitude != nil { - assert.Equal(t, fmt.Sprintf("%f", tc.Latitude.Value), lat) - assert.Equal(t, fmt.Sprintf("%f", tc.Longitude.Value), lng) + if tc.Latitude != 0.0 && tc.Longitude != 0.0 { + assert.Equal(t, fmt.Sprintf("%f", tc.Latitude), lat) + assert.Equal(t, fmt.Sprintf("%f", tc.Longitude), lng) } if tc.Result != nil { - assert.Equal(t, tc.Result.LineOne, rsp.LineOne) - assert.Equal(t, tc.Result.LineTwo, rsp.LineTwo) - assert.Equal(t, tc.Result.City, rsp.City) - assert.Equal(t, tc.Result.Country, rsp.Country) - assert.Equal(t, tc.Result.Postcode, rsp.Postcode) + assert.Equal(t, tc.Result.LineOne, rsp.Address.LineOne) + assert.Equal(t, tc.Result.LineTwo, rsp.Address.LineTwo) + assert.Equal(t, tc.Result.City, rsp.Address.City) + assert.Equal(t, tc.Result.Country, rsp.Address.Country) + assert.Equal(t, tc.Result.Postcode, rsp.Address.Postcode) } }) } diff --git a/geocoding/proto/geocoding.pb.go b/geocoding/proto/geocoding.pb.go index 55bc401..6ba7182 100644 --- a/geocoding/proto/geocoding.pb.go +++ b/geocoding/proto/geocoding.pb.go @@ -1,16 +1,14 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.15.5 +// protoc-gen-go v1.26.0 +// protoc v3.15.6 // source: proto/geocoding.proto package geocoding import ( - proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - wrapperspb "google.golang.org/protobuf/types/known/wrapperspb" reflect "reflect" sync "sync" ) @@ -22,22 +20,16 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - type Address struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - LineOne string `protobuf:"bytes,1,opt,name=line_one,json=lineOne,proto3" json:"line_one,omitempty"` - LineTwo string `protobuf:"bytes,2,opt,name=line_two,json=lineTwo,proto3" json:"line_two,omitempty"` - City string `protobuf:"bytes,3,opt,name=city,proto3" json:"city,omitempty"` - Country string `protobuf:"bytes,4,opt,name=country,proto3" json:"country,omitempty"` - Postcode string `protobuf:"bytes,5,opt,name=postcode,proto3" json:"postcode,omitempty"` - Latitude float64 `protobuf:"fixed64,6,opt,name=latitude,proto3" json:"latitude,omitempty"` - Longitude float64 `protobuf:"fixed64,7,opt,name=longitude,proto3" json:"longitude,omitempty"` + LineOne string `protobuf:"bytes,1,opt,name=line_one,json=lineOne,proto3" json:"line_one,omitempty"` + LineTwo string `protobuf:"bytes,2,opt,name=line_two,json=lineTwo,proto3" json:"line_two,omitempty"` + City string `protobuf:"bytes,3,opt,name=city,proto3" json:"city,omitempty"` + Country string `protobuf:"bytes,4,opt,name=country,proto3" json:"country,omitempty"` + Postcode string `protobuf:"bytes,5,opt,name=postcode,proto3" json:"postcode,omitempty"` } func (x *Address) Reset() { @@ -107,31 +99,17 @@ func (x *Address) GetPostcode() string { return "" } -func (x *Address) GetLatitude() float64 { - if x != nil { - return x.Latitude - } - return 0 -} - -func (x *Address) GetLongitude() float64 { - if x != nil { - return x.Longitude - } - return 0 -} - -type Coordinates struct { +type Location struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Latitude *wrapperspb.DoubleValue `protobuf:"bytes,1,opt,name=latitude,proto3" json:"latitude,omitempty"` - Longitude *wrapperspb.DoubleValue `protobuf:"bytes,2,opt,name=longitude,proto3" json:"longitude,omitempty"` + Latitude float64 `protobuf:"fixed64,1,opt,name=latitude,proto3" json:"latitude,omitempty"` + Longitude float64 `protobuf:"fixed64,2,opt,name=longitude,proto3" json:"longitude,omitempty"` } -func (x *Coordinates) Reset() { - *x = Coordinates{} +func (x *Location) Reset() { + *x = Location{} if protoimpl.UnsafeEnabled { mi := &file_proto_geocoding_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -139,13 +117,13 @@ func (x *Coordinates) Reset() { } } -func (x *Coordinates) String() string { +func (x *Location) String() string { return protoimpl.X.MessageStringOf(x) } -func (*Coordinates) ProtoMessage() {} +func (*Location) ProtoMessage() {} -func (x *Coordinates) ProtoReflect() protoreflect.Message { +func (x *Location) ProtoReflect() protoreflect.Message { mi := &file_proto_geocoding_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -157,22 +135,260 @@ func (x *Coordinates) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use Coordinates.ProtoReflect.Descriptor instead. -func (*Coordinates) Descriptor() ([]byte, []int) { +// Deprecated: Use Location.ProtoReflect.Descriptor instead. +func (*Location) Descriptor() ([]byte, []int) { return file_proto_geocoding_proto_rawDescGZIP(), []int{1} } -func (x *Coordinates) GetLatitude() *wrapperspb.DoubleValue { +func (x *Location) GetLatitude() float64 { if x != nil { return x.Latitude } + return 0 +} + +func (x *Location) GetLongitude() float64 { + if x != nil { + return x.Longitude + } + return 0 +} + +// Lookup returns a geocoded address including normalized address and gps coordinates +type LookupRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + City string `protobuf:"bytes,2,opt,name=city,proto3" json:"city,omitempty"` + Postcode string `protobuf:"bytes,3,opt,name=postcode,proto3" json:"postcode,omitempty"` + Country string `protobuf:"bytes,4,opt,name=country,proto3" json:"country,omitempty"` +} + +func (x *LookupRequest) Reset() { + *x = LookupRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_geocoding_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LookupRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LookupRequest) ProtoMessage() {} + +func (x *LookupRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_geocoding_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LookupRequest.ProtoReflect.Descriptor instead. +func (*LookupRequest) Descriptor() ([]byte, []int) { + return file_proto_geocoding_proto_rawDescGZIP(), []int{2} +} + +func (x *LookupRequest) GetAddress() string { + if x != nil { + return x.Address + } + return "" +} + +func (x *LookupRequest) GetCity() string { + if x != nil { + return x.City + } + return "" +} + +func (x *LookupRequest) GetPostcode() string { + if x != nil { + return x.Postcode + } + return "" +} + +func (x *LookupRequest) GetCountry() string { + if x != nil { + return x.Country + } + return "" +} + +type LookupResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Address *Address `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Location *Location `protobuf:"bytes,2,opt,name=location,proto3" json:"location,omitempty"` +} + +func (x *LookupResponse) Reset() { + *x = LookupResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_geocoding_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LookupResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LookupResponse) ProtoMessage() {} + +func (x *LookupResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_geocoding_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LookupResponse.ProtoReflect.Descriptor instead. +func (*LookupResponse) Descriptor() ([]byte, []int) { + return file_proto_geocoding_proto_rawDescGZIP(), []int{3} +} + +func (x *LookupResponse) GetAddress() *Address { + if x != nil { + return x.Address + } return nil } -func (x *Coordinates) GetLongitude() *wrapperspb.DoubleValue { +func (x *LookupResponse) GetLocation() *Location { + if x != nil { + return x.Location + } + return nil +} + +// Reverse lookup an address from gps coordinates +type ReverseRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Latitude float64 `protobuf:"fixed64,1,opt,name=latitude,proto3" json:"latitude,omitempty"` + Longitude float64 `protobuf:"fixed64,2,opt,name=longitude,proto3" json:"longitude,omitempty"` +} + +func (x *ReverseRequest) Reset() { + *x = ReverseRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_geocoding_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ReverseRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReverseRequest) ProtoMessage() {} + +func (x *ReverseRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_geocoding_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ReverseRequest.ProtoReflect.Descriptor instead. +func (*ReverseRequest) Descriptor() ([]byte, []int) { + return file_proto_geocoding_proto_rawDescGZIP(), []int{4} +} + +func (x *ReverseRequest) GetLatitude() float64 { + if x != nil { + return x.Latitude + } + return 0 +} + +func (x *ReverseRequest) GetLongitude() float64 { if x != nil { return x.Longitude } + return 0 +} + +type ReverseResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Address *Address `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Location *Location `protobuf:"bytes,2,opt,name=location,proto3" json:"location,omitempty"` +} + +func (x *ReverseResponse) Reset() { + *x = ReverseResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_geocoding_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ReverseResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReverseResponse) ProtoMessage() {} + +func (x *ReverseResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_geocoding_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ReverseResponse.ProtoReflect.Descriptor instead. +func (*ReverseResponse) Descriptor() ([]byte, []int) { + return file_proto_geocoding_proto_rawDescGZIP(), []int{5} +} + +func (x *ReverseResponse) GetAddress() *Address { + if x != nil { + return x.Address + } + return nil +} + +func (x *ReverseResponse) GetLocation() *Location { + if x != nil { + return x.Location + } return nil } @@ -181,9 +397,7 @@ var File_proto_geocoding_proto protoreflect.FileDescriptor var file_proto_geocoding_proto_rawDesc = []byte{ 0x0a, 0x15, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6f, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x67, 0x65, 0x6f, 0x63, 0x6f, 0x64, 0x69, - 0x6e, 0x67, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2f, 0x77, 0x72, 0x61, 0x70, 0x70, 0x65, 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x22, 0xc3, 0x01, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x19, + 0x6e, 0x67, 0x22, 0x89, 0x01, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x6c, 0x69, 0x6e, 0x65, 0x5f, 0x6f, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6c, 0x69, 0x6e, 0x65, 0x4f, 0x6e, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x6c, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x77, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6c, 0x69, 0x6e, @@ -191,29 +405,49 @@ var file_proto_geocoding_proto_rawDesc = []byte{ 0x28, 0x09, 0x52, 0x04, 0x63, 0x69, 0x74, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6f, 0x73, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6f, 0x73, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x1a, - 0x0a, 0x08, 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x01, - 0x52, 0x08, 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6c, 0x6f, - 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x01, 0x52, 0x09, 0x6c, - 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x22, 0x83, 0x01, 0x0a, 0x0b, 0x43, 0x6f, 0x6f, - 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x12, 0x38, 0x0a, 0x08, 0x6c, 0x61, 0x74, 0x69, - 0x74, 0x75, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x6f, 0x75, - 0x62, 0x6c, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x08, 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, - 0x64, 0x65, 0x12, 0x3a, 0x0a, 0x09, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x56, 0x61, - 0x6c, 0x75, 0x65, 0x52, 0x09, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x32, 0x79, - 0x0a, 0x09, 0x47, 0x65, 0x6f, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x12, 0x33, 0x0a, 0x07, 0x47, - 0x65, 0x6f, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x2e, 0x67, 0x65, 0x6f, 0x63, 0x6f, 0x64, 0x69, - 0x6e, 0x67, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x1a, 0x12, 0x2e, 0x67, 0x65, 0x6f, - 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0x00, - 0x12, 0x37, 0x0a, 0x07, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x12, 0x16, 0x2e, 0x67, 0x65, - 0x6f, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2e, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, - 0x74, 0x65, 0x73, 0x1a, 0x12, 0x2e, 0x67, 0x65, 0x6f, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2e, - 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0x00, 0x42, 0x11, 0x5a, 0x0f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x3b, 0x67, 0x65, 0x6f, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6f, 0x73, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x44, + 0x0a, 0x08, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x61, + 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x01, 0x52, 0x08, 0x6c, 0x61, + 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, + 0x75, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x52, 0x09, 0x6c, 0x6f, 0x6e, 0x67, 0x69, + 0x74, 0x75, 0x64, 0x65, 0x22, 0x73, 0x0a, 0x0d, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, + 0x12, 0x0a, 0x04, 0x63, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, + 0x69, 0x74, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6f, 0x73, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6f, 0x73, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x12, + 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x22, 0x6f, 0x0a, 0x0e, 0x4c, 0x6f, 0x6f, + 0x6b, 0x75, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x07, 0x61, + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x67, + 0x65, 0x6f, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, + 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x2f, 0x0a, 0x08, 0x6c, 0x6f, 0x63, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x67, 0x65, + 0x6f, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2e, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x52, 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x4a, 0x0a, 0x0e, 0x52, 0x65, + 0x76, 0x65, 0x72, 0x73, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, + 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x01, 0x52, 0x08, + 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6c, 0x6f, 0x6e, 0x67, + 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x52, 0x09, 0x6c, 0x6f, 0x6e, + 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x22, 0x70, 0x0a, 0x0f, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, + 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x07, 0x61, 0x64, 0x64, + 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x67, 0x65, 0x6f, + 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x07, + 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x2f, 0x0a, 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x67, 0x65, 0x6f, 0x63, + 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2e, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x08, + 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x32, 0x90, 0x01, 0x0a, 0x09, 0x47, 0x65, 0x6f, + 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x12, 0x3f, 0x0a, 0x06, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, + 0x12, 0x18, 0x2e, 0x67, 0x65, 0x6f, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2e, 0x4c, 0x6f, 0x6f, + 0x6b, 0x75, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x67, 0x65, 0x6f, + 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x42, 0x0a, 0x07, 0x52, 0x65, 0x76, 0x65, 0x72, + 0x73, 0x65, 0x12, 0x19, 0x2e, 0x67, 0x65, 0x6f, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2e, 0x52, + 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, + 0x67, 0x65, 0x6f, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2e, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, + 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x13, 0x5a, 0x11, 0x2e, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x67, 0x65, 0x6f, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -228,24 +462,29 @@ func file_proto_geocoding_proto_rawDescGZIP() []byte { return file_proto_geocoding_proto_rawDescData } -var file_proto_geocoding_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_proto_geocoding_proto_msgTypes = make([]protoimpl.MessageInfo, 6) var file_proto_geocoding_proto_goTypes = []interface{}{ - (*Address)(nil), // 0: geocoding.Address - (*Coordinates)(nil), // 1: geocoding.Coordinates - (*wrapperspb.DoubleValue)(nil), // 2: google.protobuf.DoubleValue + (*Address)(nil), // 0: geocoding.Address + (*Location)(nil), // 1: geocoding.Location + (*LookupRequest)(nil), // 2: geocoding.LookupRequest + (*LookupResponse)(nil), // 3: geocoding.LookupResponse + (*ReverseRequest)(nil), // 4: geocoding.ReverseRequest + (*ReverseResponse)(nil), // 5: geocoding.ReverseResponse } var file_proto_geocoding_proto_depIdxs = []int32{ - 2, // 0: geocoding.Coordinates.latitude:type_name -> google.protobuf.DoubleValue - 2, // 1: geocoding.Coordinates.longitude:type_name -> google.protobuf.DoubleValue - 0, // 2: geocoding.Geocoding.Geocode:input_type -> geocoding.Address - 1, // 3: geocoding.Geocoding.Reverse:input_type -> geocoding.Coordinates - 0, // 4: geocoding.Geocoding.Geocode:output_type -> geocoding.Address - 0, // 5: geocoding.Geocoding.Reverse:output_type -> geocoding.Address - 4, // [4:6] is the sub-list for method output_type - 2, // [2:4] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 0, // 0: geocoding.LookupResponse.address:type_name -> geocoding.Address + 1, // 1: geocoding.LookupResponse.location:type_name -> geocoding.Location + 0, // 2: geocoding.ReverseResponse.address:type_name -> geocoding.Address + 1, // 3: geocoding.ReverseResponse.location:type_name -> geocoding.Location + 2, // 4: geocoding.Geocoding.Lookup:input_type -> geocoding.LookupRequest + 4, // 5: geocoding.Geocoding.Reverse:input_type -> geocoding.ReverseRequest + 3, // 6: geocoding.Geocoding.Lookup:output_type -> geocoding.LookupResponse + 5, // 7: geocoding.Geocoding.Reverse:output_type -> geocoding.ReverseResponse + 6, // [6:8] is the sub-list for method output_type + 4, // [4:6] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_proto_geocoding_proto_init() } @@ -267,7 +506,55 @@ func file_proto_geocoding_proto_init() { } } file_proto_geocoding_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Coordinates); i { + switch v := v.(*Location); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_geocoding_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LookupRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_geocoding_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LookupResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_geocoding_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ReverseRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_geocoding_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ReverseResponse); i { case 0: return &v.state case 1: @@ -285,7 +572,7 @@ func file_proto_geocoding_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_proto_geocoding_proto_rawDesc, NumEnums: 0, - NumMessages: 2, + NumMessages: 6, NumExtensions: 0, NumServices: 1, }, diff --git a/geocoding/proto/geocoding.pb.micro.go b/geocoding/proto/geocoding.pb.micro.go index 66f3776..7be42e8 100644 --- a/geocoding/proto/geocoding.pb.micro.go +++ b/geocoding/proto/geocoding.pb.micro.go @@ -6,7 +6,6 @@ package geocoding import ( fmt "fmt" proto "github.com/golang/protobuf/proto" - _ "google.golang.org/protobuf/types/known/wrapperspb" math "math" ) @@ -43,10 +42,10 @@ func NewGeocodingEndpoints() []*api.Endpoint { // Client API for Geocoding service type GeocodingService interface { - // Geocode an address, the result will be the normalized address which contains coordinates - Geocode(ctx context.Context, in *Address, opts ...client.CallOption) (*Address, error) + // Lookup an address, the result will be the normalized address which contains coordinates + Lookup(ctx context.Context, in *LookupRequest, opts ...client.CallOption) (*LookupResponse, error) // Reverse geocode coordinates to an address - Reverse(ctx context.Context, in *Coordinates, opts ...client.CallOption) (*Address, error) + Reverse(ctx context.Context, in *ReverseRequest, opts ...client.CallOption) (*ReverseResponse, error) } type geocodingService struct { @@ -61,9 +60,9 @@ func NewGeocodingService(name string, c client.Client) GeocodingService { } } -func (c *geocodingService) Geocode(ctx context.Context, in *Address, opts ...client.CallOption) (*Address, error) { - req := c.c.NewRequest(c.name, "Geocoding.Geocode", in) - out := new(Address) +func (c *geocodingService) Lookup(ctx context.Context, in *LookupRequest, opts ...client.CallOption) (*LookupResponse, error) { + req := c.c.NewRequest(c.name, "Geocoding.Lookup", in) + out := new(LookupResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { return nil, err @@ -71,9 +70,9 @@ func (c *geocodingService) Geocode(ctx context.Context, in *Address, opts ...cli return out, nil } -func (c *geocodingService) Reverse(ctx context.Context, in *Coordinates, opts ...client.CallOption) (*Address, error) { +func (c *geocodingService) Reverse(ctx context.Context, in *ReverseRequest, opts ...client.CallOption) (*ReverseResponse, error) { req := c.c.NewRequest(c.name, "Geocoding.Reverse", in) - out := new(Address) + out := new(ReverseResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { return nil, err @@ -84,16 +83,16 @@ func (c *geocodingService) Reverse(ctx context.Context, in *Coordinates, opts .. // Server API for Geocoding service type GeocodingHandler interface { - // Geocode an address, the result will be the normalized address which contains coordinates - Geocode(context.Context, *Address, *Address) error + // Lookup an address, the result will be the normalized address which contains coordinates + Lookup(context.Context, *LookupRequest, *LookupResponse) error // Reverse geocode coordinates to an address - Reverse(context.Context, *Coordinates, *Address) error + Reverse(context.Context, *ReverseRequest, *ReverseResponse) error } func RegisterGeocodingHandler(s server.Server, hdlr GeocodingHandler, opts ...server.HandlerOption) error { type geocoding interface { - Geocode(ctx context.Context, in *Address, out *Address) error - Reverse(ctx context.Context, in *Coordinates, out *Address) error + Lookup(ctx context.Context, in *LookupRequest, out *LookupResponse) error + Reverse(ctx context.Context, in *ReverseRequest, out *ReverseResponse) error } type Geocoding struct { geocoding @@ -106,10 +105,10 @@ type geocodingHandler struct { GeocodingHandler } -func (h *geocodingHandler) Geocode(ctx context.Context, in *Address, out *Address) error { - return h.GeocodingHandler.Geocode(ctx, in, out) +func (h *geocodingHandler) Lookup(ctx context.Context, in *LookupRequest, out *LookupResponse) error { + return h.GeocodingHandler.Lookup(ctx, in, out) } -func (h *geocodingHandler) Reverse(ctx context.Context, in *Coordinates, out *Address) error { +func (h *geocodingHandler) Reverse(ctx context.Context, in *ReverseRequest, out *ReverseResponse) error { return h.GeocodingHandler.Reverse(ctx, in, out) } diff --git a/geocoding/proto/geocoding.proto b/geocoding/proto/geocoding.proto index 6b6fd91..a66aa44 100644 --- a/geocoding/proto/geocoding.proto +++ b/geocoding/proto/geocoding.proto @@ -3,26 +3,46 @@ syntax = "proto3"; package geocoding; option go_package = "./proto;geocoding"; -import "google/protobuf/wrappers.proto"; - service Geocoding { - // Geocode an address, the result will be the normalized address which contains coordinates - rpc Geocode(Address) returns (Address) {}; + // Lookup an address, the result will be the normalized address which contains coordinates + rpc Lookup(LookupRequest) returns (LookupResponse) {}; // Reverse geocode coordinates to an address - rpc Reverse(Coordinates) returns (Address) {}; + rpc Reverse(ReverseRequest) returns (ReverseResponse) {}; } message Address { - string line_one = 1; - string line_two = 2; - string city = 3; - string country = 4; - string postcode = 5; - double latitude = 6; - double longitude = 7; + string line_one = 1; + string line_two = 2; + string city = 3; + string country = 4; + string postcode = 5; } -message Coordinates { - google.protobuf.DoubleValue latitude = 1; - google.protobuf.DoubleValue longitude = 2; +message Location { + double latitude = 1; + double longitude = 2; +} + +// Lookup returns a geocoded address including normalized address and gps coordinates +message LookupRequest { + string address = 1; + string city = 2; + string postcode = 3; + string country = 4; +} + +message LookupResponse { + Address address = 1; + Location location = 2; +} + +// Reverse lookup an address from gps coordinates +message ReverseRequest { + double latitude = 1; + double longitude = 2; +} + +message ReverseResponse { + Address address = 1; + Location location = 2; }