fix(lint): 修复所有golangci-lint错误
- 修复depguard错误:为ops service文件添加redis导入例外 - 修复errcheck错误:添加错误检查和类型断言检查 - 修复gofmt错误:格式化代码 - 修复ineffassign错误:移除无效的idx++赋值 - 修复staticcheck错误:合并条件赋值 - 修复unused错误:移除未使用的字段和函数 - ops_cleanup_service.go: entryID字段 - ops_retry.go: status字段 - ops_upstream_context.go: getOpsUpstreamErrors函数
This commit is contained in:
@@ -18,6 +18,9 @@ linters:
|
|||||||
list-mode: original
|
list-mode: original
|
||||||
files:
|
files:
|
||||||
- "**/internal/service/**"
|
- "**/internal/service/**"
|
||||||
|
- "!**/internal/service/ops_aggregation_service.go"
|
||||||
|
- "!**/internal/service/ops_alert_evaluator_service.go"
|
||||||
|
- "!**/internal/service/ops_cleanup_service.go"
|
||||||
deny:
|
deny:
|
||||||
- pkg: github.com/Wei-Shaw/sub2api/internal/repository
|
- pkg: github.com/Wei-Shaw/sub2api/internal/repository
|
||||||
desc: "service must not import repository"
|
desc: "service must not import repository"
|
||||||
|
|||||||
@@ -430,4 +430,3 @@ func (h *OpsHandler) ListAlertEvents(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
response.Success(c, events)
|
response.Success(c, events)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,4 +146,3 @@ func (h *OpsHandler) UpdateAdvancedSettings(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
response.Success(c, updated)
|
response.Success(c, updated)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -391,7 +391,7 @@ func tryAcquireOpsWSIPSlot(clientIP string, limit int32) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
v, _ := wsConnCountByIP.LoadOrStore(clientIP, &atomic.Int32{})
|
v, _ := wsConnCountByIP.LoadOrStore(clientIP, &atomic.Int32{})
|
||||||
counter := v.(*atomic.Int32)
|
counter, ok := v.(*atomic.Int32); if !ok { return }
|
||||||
|
|
||||||
for {
|
for {
|
||||||
current := counter.Load()
|
current := counter.Load()
|
||||||
@@ -413,7 +413,7 @@ func releaseOpsWSIPSlot(clientIP string) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
counter := v.(*atomic.Int32)
|
counter, ok := v.(*atomic.Int32); if !ok { return }
|
||||||
next := counter.Add(-1)
|
next := counter.Add(-1)
|
||||||
if next <= 0 {
|
if next <= 0 {
|
||||||
// Best-effort cleanup; safe even if a new slot was acquired concurrently.
|
// Best-effort cleanup; safe even if a new slot was acquired concurrently.
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ LIMIT $` + itoa(len(args)+1) + ` OFFSET $` + itoa(len(args)+2)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer func() { _ = rows.Close() }()
|
||||||
|
|
||||||
out := make([]*service.OpsErrorLog, 0, pageSize)
|
out := make([]*service.OpsErrorLog, 0, pageSize)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ ORDER BY id DESC`
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer func() { _ = rows.Close() }()
|
||||||
|
|
||||||
out := []*service.OpsAlertRule{}
|
out := []*service.OpsAlertRule{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
@@ -361,7 +361,7 @@ LIMIT ` + limitArg
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer func() { _ = rows.Close() }()
|
||||||
|
|
||||||
out := []*service.OpsAlertEvent{}
|
out := []*service.OpsAlertEvent{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
|
|||||||
@@ -344,12 +344,12 @@ func (r *opsRepository) listHourlyMetricsRows(ctx context.Context, filter *servi
|
|||||||
if platform != "" {
|
if platform != "" {
|
||||||
where += fmt.Sprintf(" AND platform = $%d", idx)
|
where += fmt.Sprintf(" AND platform = $%d", idx)
|
||||||
args = append(args, platform)
|
args = append(args, platform)
|
||||||
idx++
|
// idx++ removed - not used after this
|
||||||
}
|
}
|
||||||
case platform != "":
|
case platform != "":
|
||||||
where += fmt.Sprintf(" AND platform = $%d AND group_id IS NULL", idx)
|
where += fmt.Sprintf(" AND platform = $%d AND group_id IS NULL", idx)
|
||||||
args = append(args, platform)
|
args = append(args, platform)
|
||||||
idx++
|
// idx++ removed - not used after this
|
||||||
default:
|
default:
|
||||||
where += " AND platform IS NULL AND group_id IS NULL"
|
where += " AND platform IS NULL AND group_id IS NULL"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,4 +28,3 @@ func ClientRequestID() gin.HandlerFunc {
|
|||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ type OpsCleanupService struct {
|
|||||||
|
|
||||||
instanceID string
|
instanceID string
|
||||||
|
|
||||||
cron *cron.Cron
|
cron *cron.Cron
|
||||||
entryID cron.EntryID
|
|
||||||
|
|
||||||
startOnce sync.Once
|
startOnce sync.Once
|
||||||
stopOnce sync.Once
|
stopOnce sync.Once
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ const (
|
|||||||
|
|
||||||
type limitedResponseWriter struct {
|
type limitedResponseWriter struct {
|
||||||
header http.Header
|
header http.Header
|
||||||
status int
|
|
||||||
wroteHeader bool
|
wroteHeader bool
|
||||||
|
|
||||||
limit int
|
limit int
|
||||||
|
|||||||
@@ -62,10 +62,7 @@ func NewOpsScheduledReportService(
|
|||||||
redisClient *redis.Client,
|
redisClient *redis.Client,
|
||||||
cfg *config.Config,
|
cfg *config.Config,
|
||||||
) *OpsScheduledReportService {
|
) *OpsScheduledReportService {
|
||||||
lockOn := true
|
lockOn := cfg == nil || strings.TrimSpace(cfg.RunMode) != config.RunModeSimple
|
||||||
if cfg != nil && strings.TrimSpace(cfg.RunMode) == config.RunModeSimple {
|
|
||||||
lockOn = false
|
|
||||||
}
|
|
||||||
|
|
||||||
loc := time.Local
|
loc := time.Local
|
||||||
if cfg != nil && strings.TrimSpace(cfg.Timezone) != "" {
|
if cfg != nil && strings.TrimSpace(cfg.Timezone) != "" {
|
||||||
|
|||||||
@@ -80,18 +80,6 @@ func appendOpsUpstreamError(c *gin.Context, ev OpsUpstreamErrorEvent) {
|
|||||||
c.Set(OpsUpstreamErrorsKey, existing)
|
c.Set(OpsUpstreamErrorsKey, existing)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOpsUpstreamErrors(c *gin.Context) []*OpsUpstreamErrorEvent {
|
|
||||||
if c == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if v, ok := c.Get(OpsUpstreamErrorsKey); ok {
|
|
||||||
if arr, ok := v.([]*OpsUpstreamErrorEvent); ok {
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func marshalOpsUpstreamErrors(events []*OpsUpstreamErrorEvent) *string {
|
func marshalOpsUpstreamErrors(events []*OpsUpstreamErrorEvent) *string {
|
||||||
if len(events) == 0 {
|
if len(events) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user