chore: add golangci-lint config and fix all lint issues
Add .golangci.yml enabling errcheck, staticcheck, govet, gosec, ineffassign, and unused linters. Fix 66 issues across 16 files: - Check all unchecked errors (errcheck) - Use HTTP status constants instead of numeric literals (staticcheck) - Replace deprecated LineUp/LineDown with ScrollUp/ScrollDown (staticcheck) - Convert sprintf+write patterns to fmt.Fprintf (staticcheck) - Add ReadHeaderTimeout to http.Server (gosec) - Remove unused types and functions (unused) - Add nolint comments for intentional patterns (InsecureSkipVerify, math/rand for jitter, dialect-only SQL formatting)
This commit is contained in:
@@ -2,8 +2,6 @@ package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go-upkeep/internal/models"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -71,26 +69,3 @@ func fmtNodeLastSeen(t time.Time) string {
|
||||
}
|
||||
return fmt.Sprintf("%dh ago", int(ago.Hours()))
|
||||
}
|
||||
|
||||
func fmtProbeRegions(site models.Site, probeResults map[string]probeStatus) string {
|
||||
if len(probeResults) == 0 {
|
||||
return subtleStyle.Render("—")
|
||||
}
|
||||
var parts []string
|
||||
for region, status := range probeResults {
|
||||
short := region
|
||||
if len(short) > 6 {
|
||||
short = short[:6]
|
||||
}
|
||||
if status.isUp {
|
||||
parts = append(parts, specialStyle.Render(short+":UP"))
|
||||
} else {
|
||||
parts = append(parts, dangerStyle.Render(short+":DN"))
|
||||
}
|
||||
}
|
||||
return strings.Join(parts, " ")
|
||||
}
|
||||
|
||||
type probeStatus struct {
|
||||
isUp bool
|
||||
}
|
||||
|
||||
@@ -301,10 +301,10 @@ func fmtStatus(status string, paused bool, inMaint bool) string {
|
||||
if inMaint {
|
||||
return maintStyle.Render("MAINT")
|
||||
}
|
||||
switch {
|
||||
case status == "DOWN" || status == "SSL EXP":
|
||||
switch status {
|
||||
case "DOWN", "SSL EXP":
|
||||
return dangerStyle.Render(status)
|
||||
case status == "PENDING":
|
||||
case "PENDING":
|
||||
return subtleStyle.Render(status)
|
||||
default:
|
||||
return specialStyle.Render(status)
|
||||
@@ -721,7 +721,7 @@ func (m Model) viewDetailPanel() string {
|
||||
b.WriteString(breadcrumb + "\n\n")
|
||||
|
||||
row := func(label, value string) {
|
||||
b.WriteString(fmt.Sprintf(" %-16s %s\n", subtleStyle.Render(label), value))
|
||||
fmt.Fprintf(&b, " %-16s %s\n", subtleStyle.Render(label), value)
|
||||
}
|
||||
|
||||
row("Status", fmtStatus(site.Status, site.Paused, m.isMonitorInMaintenance(site.ID)))
|
||||
@@ -780,7 +780,7 @@ func (m Model) viewDetailPanel() string {
|
||||
}
|
||||
latency := time.Duration(result.LatencyNs).Milliseconds()
|
||||
ago := time.Since(result.CheckedAt).Truncate(time.Second)
|
||||
b.WriteString(fmt.Sprintf(" %-14s %s %dms %s ago\n", nodeID, status, latency, ago))
|
||||
fmt.Fprintf(&b, " %-14s %s %dms %s ago\n", nodeID, status, latency, ago)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -795,9 +795,9 @@ func (m Model) viewDetailPanel() string {
|
||||
up++
|
||||
}
|
||||
}
|
||||
b.WriteString(fmt.Sprintf("\n %s %d/%d checks up",
|
||||
fmt.Fprintf(&b, "\n %s %d/%d checks up",
|
||||
subtleStyle.Render("Heartbeats"),
|
||||
up, len(hist.Statuses)))
|
||||
up, len(hist.Statuses))
|
||||
}
|
||||
} else {
|
||||
b.WriteString(" " + latencySparkline(hist.Latencies, sparkWidth))
|
||||
@@ -814,10 +814,10 @@ func (m Model) viewDetailPanel() string {
|
||||
}
|
||||
}
|
||||
avg := total / time.Duration(len(hist.Latencies))
|
||||
b.WriteString(fmt.Sprintf("\n %s %dms %s %dms %s %dms",
|
||||
fmt.Fprintf(&b, "\n %s %dms %s %dms %s %dms",
|
||||
subtleStyle.Render("Min"), minL.Milliseconds(),
|
||||
subtleStyle.Render("Avg"), avg.Milliseconds(),
|
||||
subtleStyle.Render("Max"), maxL.Milliseconds()))
|
||||
subtleStyle.Render("Max"), maxL.Milliseconds())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+18
-15
@@ -264,20 +264,21 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if msg.Button == tea.MouseButtonWheelUp || msg.Button == tea.MouseButtonWheelDown {
|
||||
if m.state == stateLogs {
|
||||
if msg.Button == tea.MouseButtonWheelUp {
|
||||
m.logViewport.LineUp(3)
|
||||
m.logViewport.ScrollUp(3)
|
||||
} else {
|
||||
m.logViewport.LineDown(3)
|
||||
m.logViewport.ScrollDown(3)
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
listLen := len(m.sites)
|
||||
if m.currentTab == 1 {
|
||||
switch m.currentTab {
|
||||
case 1:
|
||||
listLen = len(m.alerts)
|
||||
} else if m.currentTab == 3 {
|
||||
case 3:
|
||||
listLen = len(m.nodes)
|
||||
} else if m.currentTab == 4 {
|
||||
case 4:
|
||||
listLen = len(m.maintenanceWindows)
|
||||
} else if m.currentTab == 5 {
|
||||
case 5:
|
||||
listLen = len(m.users)
|
||||
}
|
||||
if msg.Button == tea.MouseButtonWheelUp {
|
||||
@@ -364,7 +365,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
case "up", "k":
|
||||
if m.state == stateLogs {
|
||||
m.logViewport.LineUp(1)
|
||||
m.logViewport.ScrollUp(1)
|
||||
} else if m.cursor > 0 {
|
||||
m.cursor--
|
||||
if m.cursor < m.tableOffset {
|
||||
@@ -373,7 +374,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
case "down", "j":
|
||||
if m.state == stateLogs {
|
||||
m.logViewport.LineDown(1)
|
||||
m.logViewport.ScrollDown(1)
|
||||
} else {
|
||||
max := len(m.sites) - 1
|
||||
if m.currentTab == 1 {
|
||||
@@ -645,13 +646,14 @@ func (m *Model) refreshData() {
|
||||
m.logViewport.SetContent(strings.Join(m.engine.GetLogs(), "\n"))
|
||||
|
||||
listLen := len(m.sites)
|
||||
if m.currentTab == 1 {
|
||||
switch m.currentTab {
|
||||
case 1:
|
||||
listLen = len(m.alerts)
|
||||
} else if m.currentTab == 3 {
|
||||
case 3:
|
||||
listLen = len(m.nodes)
|
||||
} else if m.currentTab == 4 {
|
||||
case 4:
|
||||
listLen = len(m.maintenanceWindows)
|
||||
} else if m.currentTab == 5 {
|
||||
case 5:
|
||||
listLen = len(m.users)
|
||||
}
|
||||
if listLen > 0 && m.cursor >= listLen {
|
||||
@@ -709,11 +711,12 @@ func (m Model) View() string {
|
||||
switch m.state {
|
||||
case stateConfirmDelete:
|
||||
kind := "monitor"
|
||||
if m.deleteTab == 1 {
|
||||
switch m.deleteTab {
|
||||
case 1:
|
||||
kind = "alert"
|
||||
} else if m.deleteTab == 4 {
|
||||
case 4:
|
||||
kind = "maintenance window"
|
||||
} else if m.deleteTab == 5 {
|
||||
case 5:
|
||||
kind = "user"
|
||||
}
|
||||
msg := dangerStyle.Render(fmt.Sprintf("Delete %s \"%s\"?", kind, m.deleteName))
|
||||
|
||||
Reference in New Issue
Block a user