mirror of
https://github.com/xiaoqidun/qqwry.git
synced 2025-12-09 01:12:55 +08:00
feat(适配特性): 适配纯真IP库社区版更新(2024-06-19)地理位置格式
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user