🎨 新增用户登录日志记录
This commit is contained in:
29
utils/ip.go
Normal file
29
utils/ip.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ipAdcodeResp struct {
|
||||
Adcode struct {
|
||||
O string `json:"o"`
|
||||
} `json:"adcode"`
|
||||
}
|
||||
|
||||
func GetIPAdcode(ip string) string {
|
||||
url := fmt.Sprintf("https://api.vore.top/api/IPdata?ip=%s", ip)
|
||||
client := &http.Client{Timeout: 5 * time.Second}
|
||||
resp, err := client.Get(url)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
var result ipAdcodeResp
|
||||
if err = json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||
return ""
|
||||
}
|
||||
return result.Adcode.O
|
||||
}
|
||||
Reference in New Issue
Block a user