perfsprint 18→0:strconv.Itoa/FormatInt/FormatUint/FormatBool 替代 fmt.Sprintf、无动词 fmt.Errorf→errors.New、纯字符串拼接。全部语义等价(已核对 diff)。修正 fixer 遗留的 import 问题(引入 goimports 统一整理)。

Result: {"status":"keep","total_issues":56,"golint_canonicalheader":8,"golint_errname":1,"golint_errorlint":12,"golint_forcetypeassert":3,"golint_gosec":0,"golint_intrange":3,"golint_modernize":5,"golint_nilnil":3,"golint_perfsprint":0,"golint_prealloc":3,"golint_recvcheck":7,"golint_usestdlibvars":3,"golint_wastedassign":7,"golint_total":55,"eslint_problems":1,"eslint_errors":0,"eslint_warnings":1,"tsc_errors":0,"measure_s":47}
This commit is contained in:
ryan
2026-08-16 17:34:44 +08:00
parent b76f707c8b
commit 699e95f12c
54 changed files with 188 additions and 157 deletions
+1 -1
View File
@@ -89,7 +89,7 @@ func NewSocketIOClient(baseURL string) *SocketIOClient {
// Connect performs the Engine.IO handshake and starts the polling loop.
func (c *SocketIOClient) Connect() error {
slog.Debug("Uptime Kuma client starting handshake", "baseURL", c.baseURL)
u := fmt.Sprintf("%s/socket.io/?EIO=4&transport=polling", c.baseURL)
u := c.baseURL + "/socket.io/?EIO=4&transport=polling"
reqHandshake, err := http.NewRequestWithContext(c.ctx, http.MethodGet, u, nil)
if err != nil {
return fmt.Errorf("create handshake request failed: %w", err)
+4 -3
View File
@@ -5,6 +5,7 @@ package uptimekuma
import (
"context"
"errors"
"fmt"
"log/slog"
"strings"
@@ -75,11 +76,11 @@ func SyncToUptimeKuma(ctx context.Context) error {
// 检查是否启用
enabled, _ := repository.GetBoolByKey(ctx, model.ConfigKeyUptimeKumaEnabled)
if !enabled {
return fmt.Errorf("uptime Kuma integration is disabled")
return errors.New("uptime Kuma integration is disabled")
}
if !isSyncing.CompareAndSwap(false, true) {
return fmt.Errorf("sync task is already in progress, please try again later")
return errors.New("sync task is already in progress, please try again later")
}
defer isSyncing.Store(false)
@@ -225,7 +226,7 @@ func filterOpenFlareMonitors(monitors map[string]Monitor, openFlareTagID int) ma
func routeMonitorURL(ctx context.Context, route *model.ProxyRoute) (string, error) {
if route == nil {
return "", fmt.Errorf("proxy route is nil")
return "", errors.New("proxy route is nil")
}
domains, err := repository.ListZoneDomainsByRouteID(ctx, route.ID)
if err != nil {
@@ -5,6 +5,7 @@ package uptimekuma
import (
"context"
"errors"
"fmt"
"log/slog"
"strings"
@@ -18,13 +19,13 @@ const monitorListWaitTimeout = 5 * time.Second
// validateKumaConfig 验证 kumaConfig 配置完整性
func validateKumaConfig(config *kumaConfig) error {
if strings.TrimSpace(config.URL) == "" {
return fmt.Errorf("uptime Kuma URL is not configured")
return errors.New("uptime Kuma URL is not configured")
}
if strings.TrimSpace(config.Username) == "" {
return fmt.Errorf("uptime Kuma username is not configured")
return errors.New("uptime Kuma username is not configured")
}
if strings.TrimSpace(config.Password) == "" {
return fmt.Errorf("uptime Kuma password is not configured")
return errors.New("uptime Kuma password is not configured")
}
return nil
}
@@ -65,7 +66,7 @@ func connectAndLoginUptimeKuma(kumaURL, kumaUsername, kumaPassword string) (*Soc
case <-time.After(monitorListWaitTimeout):
client.Close()
slog.Error("Timeout waiting for Uptime Kuma monitorList push event")
return nil, fmt.Errorf("timeout waiting for monitorList event from Uptime Kuma")
return nil, errors.New("timeout waiting for monitorList event from Uptime Kuma")
}
return client, nil
}