fix(lint): 修复代码格式和未使用变量问题
- 修复 ops_ws_handler.go 中的代码格式和返回值 - 移除 ops_repo_latency_histogram_buckets.go 中不必要的错误检查 - 修复 api_contract_test.go 缩进并添加运维监控配置项测试 - 移除 ops_cleanup_service.go 中未使用的变量 - 添加 ops_retry.go 中缺失的 status 字段
This commit is contained in:
@@ -391,7 +391,10 @@ func tryAcquireOpsWSIPSlot(clientIP string, limit int32) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
v, _ := wsConnCountByIP.LoadOrStore(clientIP, &atomic.Int32{})
|
v, _ := wsConnCountByIP.LoadOrStore(clientIP, &atomic.Int32{})
|
||||||
counter, ok := v.(*atomic.Int32); if !ok { return }
|
counter, ok := v.(*atomic.Int32)
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
current := counter.Load()
|
current := counter.Load()
|
||||||
|
|||||||
@@ -29,18 +29,18 @@ var latencyHistogramOrderedRanges = func() []string {
|
|||||||
|
|
||||||
func latencyHistogramRangeCaseExpr(column string) string {
|
func latencyHistogramRangeCaseExpr(column string) string {
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
_ = sb.WriteString("CASE\n")
|
sb.WriteString("CASE\n")
|
||||||
|
|
||||||
for _, b := range latencyHistogramBuckets {
|
for _, b := range latencyHistogramBuckets {
|
||||||
if b.upperMs <= 0 {
|
if b.upperMs <= 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
_ = sb.WriteString(fmt.Sprintf("\tWHEN %s < %d THEN '%s'\n", column, b.upperMs, b.label))
|
sb.WriteString(fmt.Sprintf("\tWHEN %s < %d THEN '%s'\n", column, b.upperMs, b.label))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default bucket.
|
// Default bucket.
|
||||||
last := latencyHistogramBuckets[len(latencyHistogramBuckets)-1]
|
last := latencyHistogramBuckets[len(latencyHistogramBuckets)-1]
|
||||||
_ = sb.WriteString(fmt.Sprintf("\tELSE '%s'\n", last.label))
|
sb.WriteString(fmt.Sprintf("\tELSE '%s'\n", last.label))
|
||||||
sb.WriteString("END")
|
sb.WriteString("END")
|
||||||
return sb.String()
|
return sb.String()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,11 +262,11 @@ func TestAPIContracts(t *testing.T) {
|
|||||||
name: "GET /api/v1/admin/settings",
|
name: "GET /api/v1/admin/settings",
|
||||||
setup: func(t *testing.T, deps *contractDeps) {
|
setup: func(t *testing.T, deps *contractDeps) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
deps.settingRepo.SetAll(map[string]string{
|
deps.settingRepo.SetAll(map[string]string{
|
||||||
service.SettingKeyRegistrationEnabled: "true",
|
service.SettingKeyRegistrationEnabled: "true",
|
||||||
service.SettingKeyEmailVerifyEnabled: "false",
|
service.SettingKeyEmailVerifyEnabled: "false",
|
||||||
|
|
||||||
service.SettingKeySMTPHost: "smtp.example.com",
|
service.SettingKeySMTPHost: "smtp.example.com",
|
||||||
service.SettingKeySMTPPort: "587",
|
service.SettingKeySMTPPort: "587",
|
||||||
service.SettingKeySMTPUsername: "user",
|
service.SettingKeySMTPUsername: "user",
|
||||||
service.SettingKeySMTPPassword: "secret",
|
service.SettingKeySMTPPassword: "secret",
|
||||||
@@ -285,10 +285,15 @@ func TestAPIContracts(t *testing.T) {
|
|||||||
service.SettingKeyContactInfo: "support",
|
service.SettingKeyContactInfo: "support",
|
||||||
service.SettingKeyDocURL: "https://docs.example.com",
|
service.SettingKeyDocURL: "https://docs.example.com",
|
||||||
|
|
||||||
service.SettingKeyDefaultConcurrency: "5",
|
service.SettingKeyDefaultConcurrency: "5",
|
||||||
service.SettingKeyDefaultBalance: "1.25",
|
service.SettingKeyDefaultBalance: "1.25",
|
||||||
})
|
|
||||||
},
|
service.SettingKeyOpsMonitoringEnabled: "false",
|
||||||
|
service.SettingKeyOpsRealtimeMonitoringEnabled: "true",
|
||||||
|
service.SettingKeyOpsQueryModeDefault: "auto",
|
||||||
|
service.SettingKeyOpsMetricsIntervalSeconds: "60",
|
||||||
|
})
|
||||||
|
},
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
path: "/api/v1/admin/settings",
|
path: "/api/v1/admin/settings",
|
||||||
wantStatus: http.StatusOK,
|
wantStatus: http.StatusOK,
|
||||||
@@ -309,13 +314,17 @@ func TestAPIContracts(t *testing.T) {
|
|||||||
"turnstile_site_key": "site-key",
|
"turnstile_site_key": "site-key",
|
||||||
"turnstile_secret_key_configured": true,
|
"turnstile_secret_key_configured": true,
|
||||||
"linuxdo_connect_enabled": false,
|
"linuxdo_connect_enabled": false,
|
||||||
"linuxdo_connect_client_id": "",
|
"linuxdo_connect_client_id": "",
|
||||||
"linuxdo_connect_client_secret_configured": false,
|
"linuxdo_connect_client_secret_configured": false,
|
||||||
"linuxdo_connect_redirect_url": "",
|
"linuxdo_connect_redirect_url": "",
|
||||||
"site_name": "Sub2API",
|
"ops_monitoring_enabled": false,
|
||||||
"site_logo": "",
|
"ops_realtime_monitoring_enabled": true,
|
||||||
"site_subtitle": "Subtitle",
|
"ops_query_mode_default": "auto",
|
||||||
"api_base_url": "https://api.example.com",
|
"ops_metrics_interval_seconds": 60,
|
||||||
|
"site_name": "Sub2API",
|
||||||
|
"site_logo": "",
|
||||||
|
"site_subtitle": "Subtitle",
|
||||||
|
"api_base_url": "https://api.example.com",
|
||||||
"contact_info": "support",
|
"contact_info": "support",
|
||||||
"doc_url": "https://docs.example.com",
|
"doc_url": "https://docs.example.com",
|
||||||
"default_concurrency": 5,
|
"default_concurrency": 5,
|
||||||
|
|||||||
@@ -94,20 +94,19 @@ func (s *OpsCleanupService) Start() {
|
|||||||
if parsed, err := time.LoadLocation(strings.TrimSpace(s.cfg.Timezone)); err == nil && parsed != nil {
|
if parsed, err := time.LoadLocation(strings.TrimSpace(s.cfg.Timezone)); err == nil && parsed != nil {
|
||||||
loc = parsed
|
loc = parsed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c := cron.New(cron.WithParser(opsCleanupCronParser), cron.WithLocation(loc))
|
c := cron.New(cron.WithParser(opsCleanupCronParser), cron.WithLocation(loc))
|
||||||
id, err := c.AddFunc(schedule, func() { s.runScheduled() })
|
_, err := c.AddFunc(schedule, func() { s.runScheduled() })
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[OpsCleanup] not started (invalid schedule=%q): %v", schedule, err)
|
log.Printf("[OpsCleanup] not started (invalid schedule=%q): %v", schedule, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.cron = c
|
s.cron = c
|
||||||
s.entryID = id
|
s.cron.Start()
|
||||||
s.cron.Start()
|
log.Printf("[OpsCleanup] started (schedule=%q tz=%s)", schedule, loc.String())
|
||||||
log.Printf("[OpsCleanup] started (schedule=%q tz=%s)", schedule, loc.String())
|
})
|
||||||
})
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (s *OpsCleanupService) Stop() {
|
func (s *OpsCleanupService) Stop() {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ const (
|
|||||||
type limitedResponseWriter struct {
|
type limitedResponseWriter struct {
|
||||||
header http.Header
|
header http.Header
|
||||||
wroteHeader bool
|
wroteHeader bool
|
||||||
|
status int
|
||||||
|
|
||||||
limit int
|
limit int
|
||||||
totalWritten int64
|
totalWritten int64
|
||||||
|
|||||||
Reference in New Issue
Block a user