chore: sync local changes (2026-03-12)

This commit is contained in:
2026-03-12 18:58:42 +08:00
parent 4fa42f7115
commit cc8d6a8028
41 changed files with 7981 additions and 3350 deletions

View File

@@ -1,56 +1,56 @@
package main
import (
"fmt"
"net"
"time"
)
// LatencyInfo 延迟信息
type LatencyInfo struct {
ClientToServer float64 `json:"clientToServer"` // 客户端到服务器延迟ms由前端计算
External map[string]string `json:"external"` // 外部网站延迟
}
// checkExternalLatency 检测外部网站延迟
func checkExternalLatency(host string, timeout time.Duration) string {
start := time.Now()
// 尝试 TCP 连接 80 端口
conn, err := net.DialTimeout("tcp", host+":80", timeout)
if err != nil {
// 如果 80 端口失败,尝试 443 (HTTPS)
conn, err = net.DialTimeout("tcp", host+":443", timeout)
if err != nil {
return "超时"
}
}
defer conn.Close()
latency := time.Since(start).Milliseconds()
// 检查是否超时(超过超时时间的一半就认为可能有问题)
if latency > timeout.Milliseconds()/2 {
return "超时"
}
return fmt.Sprintf("%d ms", latency)
}
// readExternalLatencies 读取外部网站延迟
func readExternalLatencies() map[string]string {
latencies := make(map[string]string)
timeout := 3 * time.Second
// 检测百度
latencies["baidu.com"] = checkExternalLatency("baidu.com", timeout)
// 检测谷歌
latencies["google.com"] = checkExternalLatency("google.com", timeout)
// 检测 GitHub
latencies["github.com"] = checkExternalLatency("github.com", timeout)
return latencies
}
package main
import (
"fmt"
"net"
"time"
)
// LatencyInfo 延迟信息
type LatencyInfo struct {
ClientToServer float64 `json:"clientToServer"` // 客户端到服务器延迟ms由前端计算
External map[string]string `json:"external"` // 外部网站延迟
}
// checkExternalLatency 检测外部网站延迟
func checkExternalLatency(host string, timeout time.Duration) string {
start := time.Now()
// 尝试 TCP 连接 80 端口
conn, err := net.DialTimeout("tcp", host+":80", timeout)
if err != nil {
// 如果 80 端口失败,尝试 443 (HTTPS)
conn, err = net.DialTimeout("tcp", host+":443", timeout)
if err != nil {
return "超时"
}
}
defer conn.Close()
latency := time.Since(start).Milliseconds()
// 检查是否超时(超过超时时间的一半就认为可能有问题)
if latency > timeout.Milliseconds()/2 {
return "超时"
}
return fmt.Sprintf("%d ms", latency)
}
// readExternalLatencies 读取外部网站延迟
func readExternalLatencies() map[string]string {
latencies := make(map[string]string)
timeout := 3 * time.Second
// 检测百度
latencies["baidu.com"] = checkExternalLatency("baidu.com", timeout)
// 检测谷歌
latencies["google.com"] = checkExternalLatency("google.com", timeout)
// 检测 GitHub
latencies["github.com"] = checkExternalLatency("github.com", timeout)
return latencies
}