feat: make ip update period modifiable (#13)
* feat: make ip update period modifiable * doc: change text lead to misunderstand
This commit is contained in:
+10
-4
@@ -3,6 +3,7 @@ package monitor
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -53,13 +54,18 @@ var (
|
||||
httpClientV6 = util.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, true)
|
||||
)
|
||||
|
||||
// UpdateIP 每30分钟更新一次IP地址与国家码的缓存
|
||||
func UpdateIP() {
|
||||
// UpdateIP 按设置时间间隔更新IP地址与国家码的缓存
|
||||
func UpdateIP(period uint32) {
|
||||
for {
|
||||
log.Println("NEZHA_AGENT>> 正在更新本地缓存IP信息")
|
||||
ipv4 := fetchGeoIP(geoIPApiList, false)
|
||||
ipv6 := fetchGeoIP(geoIPApiList, true)
|
||||
if ipv4.IP == "" && ipv6.IP == "" {
|
||||
time.Sleep(time.Minute)
|
||||
if period > 60 {
|
||||
time.Sleep(time.Minute)
|
||||
} else {
|
||||
time.Sleep(time.Second * time.Duration(period))
|
||||
}
|
||||
continue
|
||||
}
|
||||
if ipv4.IP == "" || ipv6.IP == "" {
|
||||
@@ -72,7 +78,7 @@ func UpdateIP() {
|
||||
} else if ipv6.CountryCode != "" {
|
||||
cachedCountry = ipv6.CountryCode
|
||||
}
|
||||
time.Sleep(time.Minute * 30)
|
||||
time.Sleep(time.Second * time.Duration(period))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user