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,12 +16,10 @@ import (
|
||||
type DataStruct struct {
|
||||
IP *string `json:"ip"`
|
||||
Hostname *string `json:"hostname"`
|
||||
ASN *string `json:"asn"`
|
||||
Org *string `json:"org"`
|
||||
City *string `json:"city"`
|
||||
Region *string `json:"region"`
|
||||
Country *string `json:"country"`
|
||||
Continent *string `json:"continent"`
|
||||
Timezone *string `json:"timezone"`
|
||||
Loc *string `json:"loc"`
|
||||
}
|
||||
@@ -85,10 +83,6 @@ func LookupIPData(geoIP *db.GeoIPManager, ip net.IP) *DataStruct {
|
||||
IsoCode string `maxminddb:"iso_code"`
|
||||
Names map[string]string `maxminddb:"names"`
|
||||
} `maxminddb:"country"`
|
||||
Continent struct {
|
||||
Code string `maxminddb:"code"`
|
||||
Names map[string]string `maxminddb:"names"`
|
||||
} `maxminddb:"continent"`
|
||||
Location struct {
|
||||
Latitude float64 `maxminddb:"latitude"`
|
||||
Longitude float64 `maxminddb:"longitude"`
|
||||
@@ -120,21 +114,13 @@ func LookupIPData(geoIP *db.GeoIPManager, ip net.IP) *DataStruct {
|
||||
hostname = []string{""}
|
||||
}
|
||||
|
||||
var sd *string
|
||||
if len(cityRecord.Subdivisions) > 0 {
|
||||
name := cityRecord.Subdivisions[0].Names["en"]
|
||||
sd = &name
|
||||
}
|
||||
|
||||
data := &DataStruct{
|
||||
IP: ToPtr(ip.String()),
|
||||
Hostname: ToPtr(strings.TrimSuffix(hostname[0], ".")),
|
||||
ASN: ToPtr(fmt.Sprintf("%d", asnRecord.AutonomousSystemNumber)),
|
||||
Org: ToPtr(asnRecord.AutonomousSystemOrganization),
|
||||
Org: ToPtr(fmt.Sprintf("AS%d %s", asnRecord.AutonomousSystemNumber, asnRecord.AutonomousSystemOrganization)),
|
||||
City: ToPtr(cityRecord.City.Names["en"]),
|
||||
Region: sd,
|
||||
Country: ToPtr(cityRecord.Country.Names["en"]),
|
||||
Continent: ToPtr(cityRecord.Continent.Names["en"]),
|
||||
Region: ToPtr(cityRecord.Subdivisions[0].Names["en"]),
|
||||
Country: ToPtr(cityRecord.Country.IsoCode),
|
||||
Timezone: ToPtr(cityRecord.Location.Timezone),
|
||||
Loc: ToPtr(fmt.Sprintf("%.4f,%.4f", cityRecord.Location.Latitude, cityRecord.Location.Longitude)),
|
||||
}
|
||||
|
||||
@@ -102,12 +102,10 @@ func (s *Server) Shutdown() {
|
||||
var fieldMap = map[string]func(*common.DataStruct) *string{
|
||||
"ip": func(d *common.DataStruct) *string { return d.IP },
|
||||
"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 },
|
||||
"city": func(d *common.DataStruct) *string { return d.City },
|
||||
"region": func(d *common.DataStruct) *string { return d.Region },
|
||||
"country": func(d *common.DataStruct) *string { return d.Country },
|
||||
"continent": func(d *common.DataStruct) *string { return d.Continent },
|
||||
"timezone": func(d *common.DataStruct) *string { return d.Timezone },
|
||||
"loc": func(d *common.DataStruct) *string { return d.Loc },
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user