一元网络论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 97|回复: 0

自编nezha面板缺国旗显示。非专家勿入

[复制链接]

1万

主题

1万

帖子

4万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
49930
发表于 2024-7-31 18:07:04 | 显示全部楼层 |阅读模式
Why compile it yourself? To customize the interface and features, of course. For those who prefer convenience, head straight to the official site.
As the agent keeps updating, I noticed an issue where the country flag wasn't showing up. Today, I decided to manually update the geolocation lookup code.
Navigate to `service/rpc/nezha.go` and locate the `LookupGeoIP` function. Replace it with the following:
```go
var clientID uint64
var err error
if clientID, err = s.Auth.Check(c); err != nil {
    return nil, err
}
ip := r.GetIp()
url := "https://xxxxxx.xx/api/ip?ip=" + ip
// Send HTTP POST request
resp, err := http.Post(url, "application/json;charset=utf-8", nil)
if err != nil {
    return nil, err
}
defer resp.Body.Close()
resBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
    return nil, err
}
var data map[string]interface{}
// Parse JSON response
err = json.Unmarshal(resBody, &data)
if err != nil {
    return nil, err
}
// Define data based on API response
resData := data["data"].(map[string]interface{})
location := strings.ToLower(resData["countryId"].(string))
singleton.ServerLock.RLock()
defer singleton.ServerLock.RUnlock()
if singleton.ServerList[clientID].Host == nil {
    return nil, fmt.Errorf("host not found")
}
singleton.ServerList[clientID].Host.CountryCode = location
return &pb.GeoIP{Ip: ip, CountryCode: location}, nil
```
Compile and you're good to go!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|一元网络论坛

GMT+8, 2024-9-10 09:41 , Processed in 0.072918 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表