mirror of
https://github.com/skidoodle/ipinfo.git
synced 2026-04-28 01:27:34 +02:00
Use ISO for Country
This commit is contained in:
+16
-30
@@ -14,16 +14,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DataStruct struct {
|
type DataStruct struct {
|
||||||
IP *string `json:"ip"`
|
IP *string `json:"ip"`
|
||||||
Hostname *string `json:"hostname"`
|
Hostname *string `json:"hostname"`
|
||||||
ASN *string `json:"asn"`
|
Org *string `json:"org"`
|
||||||
Org *string `json:"org"`
|
City *string `json:"city"`
|
||||||
City *string `json:"city"`
|
Region *string `json:"region"`
|
||||||
Region *string `json:"region"`
|
Country *string `json:"country"`
|
||||||
Country *string `json:"country"`
|
Timezone *string `json:"timezone"`
|
||||||
Continent *string `json:"continent"`
|
Loc *string `json:"loc"`
|
||||||
Timezone *string `json:"timezone"`
|
|
||||||
Loc *string `json:"loc"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Global IP cache with 10 minute TTL
|
// Global IP cache with 10 minute TTL
|
||||||
@@ -85,10 +83,6 @@ func LookupIPData(geoIP *db.GeoIPManager, ip net.IP) *DataStruct {
|
|||||||
IsoCode string `maxminddb:"iso_code"`
|
IsoCode string `maxminddb:"iso_code"`
|
||||||
Names map[string]string `maxminddb:"names"`
|
Names map[string]string `maxminddb:"names"`
|
||||||
} `maxminddb:"country"`
|
} `maxminddb:"country"`
|
||||||
Continent struct {
|
|
||||||
Code string `maxminddb:"code"`
|
|
||||||
Names map[string]string `maxminddb:"names"`
|
|
||||||
} `maxminddb:"continent"`
|
|
||||||
Location struct {
|
Location struct {
|
||||||
Latitude float64 `maxminddb:"latitude"`
|
Latitude float64 `maxminddb:"latitude"`
|
||||||
Longitude float64 `maxminddb:"longitude"`
|
Longitude float64 `maxminddb:"longitude"`
|
||||||
@@ -120,23 +114,15 @@ func LookupIPData(geoIP *db.GeoIPManager, ip net.IP) *DataStruct {
|
|||||||
hostname = []string{""}
|
hostname = []string{""}
|
||||||
}
|
}
|
||||||
|
|
||||||
var sd *string
|
|
||||||
if len(cityRecord.Subdivisions) > 0 {
|
|
||||||
name := cityRecord.Subdivisions[0].Names["en"]
|
|
||||||
sd = &name
|
|
||||||
}
|
|
||||||
|
|
||||||
data := &DataStruct{
|
data := &DataStruct{
|
||||||
IP: ToPtr(ip.String()),
|
IP: ToPtr(ip.String()),
|
||||||
Hostname: ToPtr(strings.TrimSuffix(hostname[0], ".")),
|
Hostname: ToPtr(strings.TrimSuffix(hostname[0], ".")),
|
||||||
ASN: ToPtr(fmt.Sprintf("%d", asnRecord.AutonomousSystemNumber)),
|
Org: ToPtr(fmt.Sprintf("AS%d %s", asnRecord.AutonomousSystemNumber, asnRecord.AutonomousSystemOrganization)),
|
||||||
Org: ToPtr(asnRecord.AutonomousSystemOrganization),
|
City: ToPtr(cityRecord.City.Names["en"]),
|
||||||
City: ToPtr(cityRecord.City.Names["en"]),
|
Region: ToPtr(cityRecord.Subdivisions[0].Names["en"]),
|
||||||
Region: sd,
|
Country: ToPtr(cityRecord.Country.IsoCode),
|
||||||
Country: ToPtr(cityRecord.Country.Names["en"]),
|
Timezone: ToPtr(cityRecord.Location.Timezone),
|
||||||
Continent: ToPtr(cityRecord.Continent.Names["en"]),
|
Loc: ToPtr(fmt.Sprintf("%.4f,%.4f", cityRecord.Location.Latitude, cityRecord.Location.Longitude)),
|
||||||
Timezone: ToPtr(cityRecord.Location.Timezone),
|
|
||||||
Loc: ToPtr(fmt.Sprintf("%.4f,%.4f", cityRecord.Location.Latitude, cityRecord.Location.Longitude)),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store in cache
|
// Store in cache
|
||||||
|
|||||||
@@ -100,16 +100,14 @@ func (s *Server) Shutdown() {
|
|||||||
|
|
||||||
// Field access functions map
|
// Field access functions map
|
||||||
var fieldMap = map[string]func(*common.DataStruct) *string{
|
var fieldMap = map[string]func(*common.DataStruct) *string{
|
||||||
"ip": func(d *common.DataStruct) *string { return d.IP },
|
"ip": func(d *common.DataStruct) *string { return d.IP },
|
||||||
"hostname": func(d *common.DataStruct) *string { return d.Hostname },
|
"hostname": func(d *common.DataStruct) *string { return d.Hostname },
|
||||||
"asn": func(d *common.DataStruct) *string { return d.ASN },
|
"org": func(d *common.DataStruct) *string { return d.Org },
|
||||||
"org": func(d *common.DataStruct) *string { return d.Org },
|
"city": func(d *common.DataStruct) *string { return d.City },
|
||||||
"city": func(d *common.DataStruct) *string { return d.City },
|
"region": func(d *common.DataStruct) *string { return d.Region },
|
||||||
"region": func(d *common.DataStruct) *string { return d.Region },
|
"country": func(d *common.DataStruct) *string { return d.Country },
|
||||||
"country": func(d *common.DataStruct) *string { return d.Country },
|
"timezone": func(d *common.DataStruct) *string { return d.Timezone },
|
||||||
"continent": func(d *common.DataStruct) *string { return d.Continent },
|
"loc": func(d *common.DataStruct) *string { return d.Loc },
|
||||||
"timezone": func(d *common.DataStruct) *string { return d.Timezone },
|
|
||||||
"loc": func(d *common.DataStruct) *string { return d.Loc },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieves a field from the dataStruct using the fieldMap
|
// Retrieves a field from the dataStruct using the fieldMap
|
||||||
|
|||||||
Reference in New Issue
Block a user