Change Query API
New Query API is https://ifconfig.is/json The IP data is provided by MaxMind.
This commit is contained in:
parent
e0346ce70b
commit
8fc8cf2d39
11
log.go
11
log.go
@ -83,12 +83,23 @@ func logQuery(info IPInfo) {
|
||||
values := make([]string, v.NumField())
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
names[i] = v.Type().Field(i).Name
|
||||
t := v.Field(i).Type().Name()
|
||||
if t == "string" {
|
||||
values[i] = v.Field(i).Interface().(string)
|
||||
} else if t == "bool" {
|
||||
values[i] = strconv.FormatBool(v.Field(i).Interface().(bool))
|
||||
} else if t == "float64" {
|
||||
values[i] = fmt.Sprintf("%f", v.Field(i).Interface().(float64))
|
||||
} else if t == "uint" {
|
||||
values[i] = fmt.Sprint(v.Field(i).Interface().(uint))
|
||||
}
|
||||
}
|
||||
l := getMaxNameLength(names)
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
if values[i] != "" {
|
||||
fmt.Printf("%s: %s\n", cyan("%-*s", l, names[i]), values[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getMaxNameLength(names []string) int {
|
||||
|
16
query.go
16
query.go
@ -9,15 +9,19 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
API string = "http://ip-api.com/json/"
|
||||
API string = "https://ifconfig.is/json/"
|
||||
)
|
||||
|
||||
type IPInfo struct {
|
||||
IP string `json:"query"`
|
||||
City string `json:"city"`
|
||||
Country string `json:"country"`
|
||||
ISP string `json:"isp"`
|
||||
AS string `json:"as"`
|
||||
Continent string `json:"Continent"`
|
||||
Country string `json:"Country"`
|
||||
City string `json:"City"`
|
||||
Latitude float64 `json:"Latitude"`
|
||||
Longitude float64 `json:"Longitude"`
|
||||
TimeZone string `json:"TimeZone"`
|
||||
IsEU bool `json:"IsEU"`
|
||||
ASN uint `json:"ASN"`
|
||||
ORG string `json:"ORG"`
|
||||
}
|
||||
|
||||
func queryInfo(address string) IPInfo {
|
||||
|
Loading…
Reference in New Issue
Block a user