mirror of
https://github.com/skidoodle/ipinfo.git
synced 2025-02-15 08:29:17 +01:00
f
This commit is contained in:
parent
7dd9039b92
commit
9240ecbf98
1 changed files with 10 additions and 18 deletions
28
main.go
28
main.go
|
@ -156,13 +156,11 @@ type dataStruct struct {
|
||||||
IP *string `json:"ip"`
|
IP *string `json:"ip"`
|
||||||
Hostname *string `json:"hostname"`
|
Hostname *string `json:"hostname"`
|
||||||
ASN *string `json:"asn"`
|
ASN *string `json:"asn"`
|
||||||
Organization *string `json:"organization"`
|
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"`
|
||||||
CountryFull *string `json:"country_full"`
|
|
||||||
Continent *string `json:"continent"`
|
Continent *string `json:"continent"`
|
||||||
ContinentFull *string `json:"continent_full"`
|
|
||||||
Loc *string `json:"loc"`
|
Loc *string `json:"loc"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,20 +322,16 @@ func getField(data *dataStruct, field string) *string {
|
||||||
return data.Hostname
|
return data.Hostname
|
||||||
case "asn":
|
case "asn":
|
||||||
return data.ASN
|
return data.ASN
|
||||||
case "organization":
|
case "org":
|
||||||
return data.Organization
|
return data.Org
|
||||||
case "city":
|
case "city":
|
||||||
return data.City
|
return data.City
|
||||||
case "region":
|
case "region":
|
||||||
return data.Region
|
return data.Region
|
||||||
case "country":
|
case "country":
|
||||||
return data.Country
|
return data.Country
|
||||||
case "country_full":
|
|
||||||
return data.CountryFull
|
|
||||||
case "continent":
|
case "continent":
|
||||||
return data.Continent
|
return data.Continent
|
||||||
case "continent_full":
|
|
||||||
return data.ContinentFull
|
|
||||||
case "loc":
|
case "loc":
|
||||||
return data.Loc
|
return data.Loc
|
||||||
default:
|
default:
|
||||||
|
@ -362,16 +356,16 @@ func lookupIPData(ip net.IP) *dataStruct {
|
||||||
defer dbMtx.RUnlock()
|
defer dbMtx.RUnlock()
|
||||||
|
|
||||||
var cityRecord struct {
|
var cityRecord struct {
|
||||||
Country struct {
|
|
||||||
IsoCode string `maxminddb:"iso_code"`
|
|
||||||
Names map[string]string `maxminddb:"names"`
|
|
||||||
} `maxminddb:"country"`
|
|
||||||
City struct {
|
City struct {
|
||||||
Names map[string]string `maxminddb:"names"`
|
Names map[string]string `maxminddb:"names"`
|
||||||
} `maxminddb:"city"`
|
} `maxminddb:"city"`
|
||||||
Subdivisions []struct {
|
Subdivisions []struct {
|
||||||
Names map[string]string `maxminddb:"names"`
|
Names map[string]string `maxminddb:"names"`
|
||||||
} `maxminddb:"subdivisions"`
|
} `maxminddb:"subdivisions"`
|
||||||
|
Country struct {
|
||||||
|
IsoCode string `maxminddb:"iso_code"`
|
||||||
|
Names map[string]string `maxminddb:"names"`
|
||||||
|
} `maxminddb:"country"`
|
||||||
Continent struct {
|
Continent struct {
|
||||||
Code string `maxminddb:"code"`
|
Code string `maxminddb:"code"`
|
||||||
Names map[string]string `maxminddb:"names"`
|
Names map[string]string `maxminddb:"names"`
|
||||||
|
@ -412,13 +406,11 @@ func lookupIPData(ip net.IP) *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)),
|
ASN: toPtr(fmt.Sprintf("%d", asnRecord.AutonomousSystemNumber)),
|
||||||
Organization: toPtr(asnRecord.AutonomousSystemOrganization),
|
Org: toPtr(asnRecord.AutonomousSystemOrganization),
|
||||||
Country: toPtr(cityRecord.Country.IsoCode),
|
|
||||||
CountryFull: toPtr(cityRecord.Country.Names["en"]),
|
|
||||||
City: toPtr(cityRecord.City.Names["en"]),
|
City: toPtr(cityRecord.City.Names["en"]),
|
||||||
Region: sd,
|
Region: sd,
|
||||||
Continent: toPtr(cityRecord.Continent.Code),
|
Country: toPtr(cityRecord.Country.Names["en"]),
|
||||||
ContinentFull: toPtr(cityRecord.Continent.Names["en"]),
|
Continent: toPtr(cityRecord.Continent.Names["en"]),
|
||||||
Loc: toPtr(fmt.Sprintf("%.4f,%.4f", cityRecord.Location.Latitude, cityRecord.Location.Longitude)),
|
Loc: toPtr(fmt.Sprintf("%.4f,%.4f", cityRecord.Location.Latitude, cityRecord.Location.Longitude)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue