|
|
|
@ -1025,26 +1025,24 @@ func FormatTimes(now time.Time, format string) string {
|
|
|
|
|
return now.Format(format)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CheckIPReachable(ip string, port int, timeout time.Duration) bool {
|
|
|
|
|
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, port), timeout)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
conn.Close()
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetAvailableEndpoint() string {
|
|
|
|
|
primaryIP := LoadConfig().SeverData.ServerIP
|
|
|
|
|
backupIP := LoadConfig().SeverData.BackUpServerIP // 替换为实际备选IP
|
|
|
|
|
port := 9800
|
|
|
|
|
timeout := 3 * time.Second
|
|
|
|
|
|
|
|
|
|
if CheckIPReachable(primaryIP, port, timeout) {
|
|
|
|
|
if IsIPReachable(primaryIP) {
|
|
|
|
|
return primaryIP
|
|
|
|
|
}
|
|
|
|
|
if CheckIPReachable(backupIP, port, timeout) {
|
|
|
|
|
if IsIPReachable(backupIP) {
|
|
|
|
|
return backupIP
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
func IsIPReachable(ip string) bool {
|
|
|
|
|
conn, err := net.DialTimeout("ip4:icmp", ip, 10*time.Millisecond)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
conn.Close()
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|