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:
parent
8a1ee3b05e
commit
7dad9c7a17
5 changed files with 8 additions and 8 deletions
|
|
@ -171,16 +171,16 @@ func validateSystemSettings(settings *config.SystemSettings, rawRequest map[stri
|
||||||
if val, ok := rawRequest["backupPollingInterval"]; ok {
|
if val, ok := rawRequest["backupPollingInterval"]; ok {
|
||||||
if interval, ok := val.(float64); ok {
|
if interval, ok := val.(float64); ok {
|
||||||
if interval < 0 {
|
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 {
|
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 {
|
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 {
|
} else {
|
||||||
return fmt.Errorf("Backup polling interval must be a number")
|
return fmt.Errorf("backup polling interval must be a number")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -271,7 +271,7 @@ func TestWithLoggerNilContext(t *testing.T) {
|
||||||
|
|
||||||
Init(Config{})
|
Init(Config{})
|
||||||
|
|
||||||
ctx := WithLogger(nil, New("svc", WithWriter(io.Discard)))
|
ctx := WithLogger(context.Background(), New("svc", WithWriter(io.Discard)))
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
t.Fatal("expected non-nil context")
|
t.Fatal("expected non-nil context")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2970,7 +2970,7 @@ func generatePMGInstances() []models.PMGInstance {
|
||||||
edgeQueue := &models.PMGQueueStatus{
|
edgeQueue := &models.PMGQueueStatus{
|
||||||
Active: rand.Intn(2),
|
Active: rand.Intn(2),
|
||||||
Deferred: rand.Intn(5),
|
Deferred: rand.Intn(5),
|
||||||
Hold: rand.Intn(1),
|
Hold: rand.Intn(2), // rand.Intn(1) always returns 0
|
||||||
Incoming: rand.Intn(3),
|
Incoming: rand.Intn(3),
|
||||||
Total: 0,
|
Total: 0,
|
||||||
OldestAge: int64(rand.Intn(600)),
|
OldestAge: int64(rand.Intn(600)),
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ func TestCopyStringFloatMap(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify it's a copy, not the same reference
|
// 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 {
|
for k := range result {
|
||||||
result[k] = 999.0
|
result[k] = 999.0
|
||||||
break
|
break
|
||||||
|
|
|
||||||
|
|
@ -2305,7 +2305,7 @@ func formatWebhookDuration(d time.Duration) string {
|
||||||
// extractTelegramChatID extracts and validates the chat_id from a Telegram webhook URL
|
// extractTelegramChatID extracts and validates the chat_id from a Telegram webhook URL
|
||||||
func extractTelegramChatID(webhookURL string) (string, error) {
|
func extractTelegramChatID(webhookURL string) (string, error) {
|
||||||
if !strings.Contains(webhookURL, "chat_id=") {
|
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)
|
u, err := url.Parse(webhookURL)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue