add continent to ip service

This commit is contained in:
Asim Aslam
2021-06-03 09:26:50 +01:00
parent 127f7672e1
commit 4dee4ae77d
4 changed files with 51 additions and 27 deletions

View File

@@ -7,9 +7,10 @@
},
"response": {
"ip": "93.148.214.31",
"asn": "30722",
"asn": 30722,
"city": "Reggiolo",
"country": "Italy",
"continent": "Europe",
"latitude": 44.9201,
"longitude": 10.8075,
"timezone": "Europe/Rome"

View File

@@ -31,7 +31,7 @@ func (i *Ip) Lookup(ctx context.Context, req *pb.LookupRequest, rsp *pb.LookupRe
return errors.InternalServerError("ip.lookup", "failed to lookup ip")
}
// set asp
rsp.Asn = int64(asn.AutonomousSystemNumber)
rsp.Asn = int32(asn.AutonomousSystemNumber)
}
info, err := i.CityReader.City(ip)
@@ -46,6 +46,8 @@ func (i *Ip) Lookup(ctx context.Context, req *pb.LookupRequest, rsp *pb.LookupRe
rsp.City = info.City.Names["en"]
// set countr
rsp.Country = info.Country.Names["en"]
// set continent
rsp.Continent = info.Continent.Names["en"]
// latitude/longitude
rsp.Latitude = info.Location.Latitude
rsp.Longitude = info.Location.Longitude

View File

@@ -26,6 +26,7 @@ type LookupRequest struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// IP to lookup
Ip string `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"`
}
@@ -73,13 +74,22 @@ type LookupResponse struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// IP of the query
Ip string `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"`
Asn int64 `protobuf:"varint,2,opt,name=asn,proto3" json:"asn,omitempty"`
// Autonomous system number
Asn int32 `protobuf:"varint,2,opt,name=asn,proto3" json:"asn,omitempty"`
// Name of the city
City string `protobuf:"bytes,3,opt,name=city,proto3" json:"city,omitempty"`
// Name of the country
Country string `protobuf:"bytes,4,opt,name=country,proto3" json:"country,omitempty"`
Latitude float64 `protobuf:"fixed64,5,opt,name=latitude,proto3" json:"latitude,omitempty"`
Longitude float64 `protobuf:"fixed64,6,opt,name=longitude,proto3" json:"longitude,omitempty"`
Timezone string `protobuf:"bytes,7,opt,name=timezone,proto3" json:"timezone,omitempty"`
// Name of the continent
Continent string `protobuf:"bytes,5,opt,name=continent,proto3" json:"continent,omitempty"`
// Latitude e.g 52.523219
Latitude float64 `protobuf:"fixed64,6,opt,name=latitude,proto3" json:"latitude,omitempty"`
// Longitude e.g 13.428555
Longitude float64 `protobuf:"fixed64,7,opt,name=longitude,proto3" json:"longitude,omitempty"`
// Timezone e.g Europe/Rome
Timezone string `protobuf:"bytes,8,opt,name=timezone,proto3" json:"timezone,omitempty"`
}
func (x *LookupResponse) Reset() {
@@ -121,7 +131,7 @@ func (x *LookupResponse) GetIp() string {
return ""
}
func (x *LookupResponse) GetAsn() int64 {
func (x *LookupResponse) GetAsn() int32 {
if x != nil {
return x.Asn
}
@@ -142,6 +152,13 @@ func (x *LookupResponse) GetCountry() string {
return ""
}
func (x *LookupResponse) GetContinent() string {
if x != nil {
return x.Continent
}
return ""
}
func (x *LookupResponse) GetLatitude() float64 {
if x != nil {
return x.Latitude
@@ -169,23 +186,25 @@ var file_proto_ip_proto_rawDesc = []byte{
0x0a, 0x0e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x69, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x12, 0x02, 0x69, 0x70, 0x22, 0x1f, 0x0a, 0x0d, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x02, 0x69, 0x70, 0x22, 0xb6, 0x01, 0x0a, 0x0e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70,
0x09, 0x52, 0x02, 0x69, 0x70, 0x22, 0xd4, 0x01, 0x0a, 0x0e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x70, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x73, 0x6e, 0x18,
0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x61, 0x73, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x69,
0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x61, 0x73, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x69,
0x74, 0x79, 0x18, 0x03, 0x20, 0x01, 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, 0x6c, 0x61, 0x74, 0x69,
0x74, 0x75, 0x64, 0x65, 0x18, 0x05, 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, 0x06, 0x20, 0x01, 0x28, 0x01, 0x52, 0x09, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75,
0x64, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x69, 0x6d, 0x65, 0x7a, 0x6f, 0x6e, 0x65, 0x18, 0x07,
0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x74, 0x69, 0x6d, 0x65, 0x7a, 0x6f, 0x6e, 0x65, 0x32, 0x37,
0x0a, 0x02, 0x49, 0x70, 0x12, 0x31, 0x0a, 0x06, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x12, 0x11,
0x2e, 0x69, 0x70, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x1a, 0x12, 0x2e, 0x69, 0x70, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0c, 0x5a, 0x0a, 0x2e, 0x2f, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x3b, 0x69, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x74,
0x69, 0x6e, 0x65, 0x6e, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6f, 0x6e,
0x74, 0x69, 0x6e, 0x65, 0x6e, 0x74, 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,
0x12, 0x1a, 0x0a, 0x08, 0x74, 0x69, 0x6d, 0x65, 0x7a, 0x6f, 0x6e, 0x65, 0x18, 0x08, 0x20, 0x01,
0x28, 0x09, 0x52, 0x08, 0x74, 0x69, 0x6d, 0x65, 0x7a, 0x6f, 0x6e, 0x65, 0x32, 0x37, 0x0a, 0x02,
0x49, 0x70, 0x12, 0x31, 0x0a, 0x06, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x12, 0x11, 0x2e, 0x69,
0x70, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x12, 0x2e, 0x69, 0x70, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0c, 0x5a, 0x0a, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x3b, 0x69, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (

View File

@@ -18,16 +18,18 @@ message LookupResponse {
// IP of the query
string ip = 1;
// Autonomous system number
int64 asn = 2;
int32 asn = 2;
// Name of the city
string city = 3;
// Name of the country
string country = 4;
// Name of the continent
string continent = 5;
// Latitude e.g 52.523219
double latitude = 5;
double latitude = 6;
// Longitude e.g 13.428555
double longitude = 6;
double longitude = 7;
// Timezone e.g Europe/Rome
string timezone = 7;
string timezone = 8;
}