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
15
log.go
15
log.go
@ -83,11 +83,22 @@ func logQuery(info IPInfo) {
|
|||||||
values := make([]string, v.NumField())
|
values := make([]string, v.NumField())
|
||||||
for i := 0; i < v.NumField(); i++ {
|
for i := 0; i < v.NumField(); i++ {
|
||||||
names[i] = v.Type().Field(i).Name
|
names[i] = v.Type().Field(i).Name
|
||||||
values[i] = v.Field(i).Interface().(string)
|
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)
|
l := getMaxNameLength(names)
|
||||||
for i := 0; i < v.NumField(); i++ {
|
for i := 0; i < v.NumField(); i++ {
|
||||||
fmt.Printf("%s: %s\n", cyan("%-*s", l, names[i]), values[i])
|
if values[i] != "" {
|
||||||
|
fmt.Printf("%s: %s\n", cyan("%-*s", l, names[i]), values[i])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
query.go
16
query.go
@ -9,15 +9,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
API string = "http://ip-api.com/json/"
|
API string = "https://ifconfig.is/json/"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IPInfo struct {
|
type IPInfo struct {
|
||||||
IP string `json:"query"`
|
Continent string `json:"Continent"`
|
||||||
City string `json:"city"`
|
Country string `json:"Country"`
|
||||||
Country string `json:"country"`
|
City string `json:"City"`
|
||||||
ISP string `json:"isp"`
|
Latitude float64 `json:"Latitude"`
|
||||||
AS string `json:"as"`
|
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 {
|
func queryInfo(address string) IPInfo {
|
||||||
|
Loading…
Reference in New Issue
Block a user