style: fix additional staticcheck warnings

- Lowercase error messages (ST1005)
- Use context.Background() instead of nil (SA1012)
- Fix rand.Intn(1) which always returns 0 (SA4030)
- Remove unnecessary nil check before len() (S1009)
This commit is contained in:
rcourtman 2025-11-27 09:21:11 +00:00
parent 8a1ee3b05e
commit 7dad9c7a17
5 changed files with 8 additions and 8 deletions

View file

@ -171,16 +171,16 @@ func validateSystemSettings(settings *config.SystemSettings, rawRequest map[stri
if val, ok := rawRequest["backupPollingInterval"]; ok {
if interval, ok := val.(float64); ok {
if interval < 0 {
return fmt.Errorf("Backup polling interval cannot be negative")
return fmt.Errorf("backup polling interval cannot be negative")
}
if interval > 0 && interval < 10 {
return fmt.Errorf("Backup polling interval must be at least 10 seconds")
return fmt.Errorf("backup polling interval must be at least 10 seconds")
}
if interval > 604800 {
return fmt.Errorf("Backup polling interval cannot exceed 604800 seconds (7 days)")
return fmt.Errorf("backup polling interval cannot exceed 604800 seconds (7 days)")
}
} else {
return fmt.Errorf("Backup polling interval must be a number")
return fmt.Errorf("backup polling interval must be a number")
}
}

View file

@ -271,7 +271,7 @@ func TestWithLoggerNilContext(t *testing.T) {
Init(Config{})
ctx := WithLogger(nil, New("svc", WithWriter(io.Discard)))
ctx := WithLogger(context.Background(), New("svc", WithWriter(io.Discard)))
if ctx == nil {
t.Fatal("expected non-nil context")
}

View file

@ -2970,7 +2970,7 @@ func generatePMGInstances() []models.PMGInstance {
edgeQueue := &models.PMGQueueStatus{
Active: rand.Intn(2),
Deferred: rand.Intn(5),
Hold: rand.Intn(1),
Hold: rand.Intn(2), // rand.Intn(1) always returns 0
Incoming: rand.Intn(3),
Total: 0,
OldestAge: int64(rand.Intn(600)),

View file

@ -78,7 +78,7 @@ func TestCopyStringFloatMap(t *testing.T) {
}
// Verify it's a copy, not the same reference
if tc.input != nil && len(tc.input) > 0 {
if len(tc.input) > 0 {
for k := range result {
result[k] = 999.0
break

View file

@ -2305,7 +2305,7 @@ func formatWebhookDuration(d time.Duration) string {
// extractTelegramChatID extracts and validates the chat_id from a Telegram webhook URL
func extractTelegramChatID(webhookURL string) (string, error) {
if !strings.Contains(webhookURL, "chat_id=") {
return "", fmt.Errorf("Telegram webhook URL missing chat_id parameter")
return "", fmt.Errorf("telegram webhook URL missing chat_id parameter")
}
u, err := url.Parse(webhookURL)