feat(适配特性): 适配纯真IP库社区版更新(2024-06-19)地理位置格式

This commit is contained in:
2024-06-20 00:38:19 +08:00
parent 26b587798e
commit 25daf60573
5 changed files with 98 additions and 45 deletions

View File

@@ -10,10 +10,9 @@ import (
)
type resp struct {
IP string `json:"ip"`
Err string `json:"err"`
City string `json:"city"`
Isp string `json:"isp"`
Data *qqwry.Location `json:"data"`
Success bool `json:"success"`
Message string `json:"message"`
}
func init() {
@@ -34,14 +33,14 @@ func IpAPI(writer http.ResponseWriter, request *http.Request) {
if ip == "" {
ip, _, _ = net.SplitHostPort(request.RemoteAddr)
}
rw := &resp{IP: ip}
city, isp, err := qqwry.QueryIP(ip)
write := &resp{}
location, err := qqwry.QueryIP(ip)
if err != nil {
rw.Err = err.Error()
write.Message = err.Error()
} else {
rw.City = city
rw.Isp = isp
write.Data = location
write.Success = true
}
b, _ := json.MarshalIndent(rw, "", " ")
b, _ := json.MarshalIndent(write, "", " ")
_, _ = writer.Write(b)
}