style: fix staticcheck style warnings

- Merge variable declaration with assignment (S1021)
- Use unconditional strings.TrimPrefix (S1017)
- Remove unnecessary nil checks around range (S1031)
- Remove unnecessary fmt.Sprintf (S1039)
- Use copy() instead of manual loop (S1001)
- Use time.Until instead of t.Sub(time.Now()) (S1024)
- Use buf.String() instead of string(buf.Bytes()) (S1030)
This commit is contained in:
rcourtman 2025-11-27 09:19:33 +00:00
parent 6ff345fb6b
commit ad998a1e2f
7 changed files with 30 additions and 43 deletions

View file

@ -8375,10 +8375,9 @@ func (m *Manager) LoadActiveAlerts() error {
// We can detect this if we have Node field and it appears in the ResourceID
if alert.Node != "" && len(parts) >= 2 {
var newResourceID string
var vmidStr string
// Try to extract VMID (should be last part)
vmidStr = parts[len(parts)-1]
vmidStr := parts[len(parts)-1]
if _, err := strconv.Atoi(vmidStr); err == nil {
// VMID is valid, now check if we need to migrate
if len(parts) == 3 && alert.Instance != "" && alert.Instance != alert.Node {

View file

@ -1576,13 +1576,7 @@ func (h *ConfigHandlers) HandleTestConnection(w http.ResponseWriter, r *http.Req
// Auto-generate name if not provided for test
if req.Name == "" {
// Extract hostname from URL
host := req.Host
if strings.HasPrefix(host, "http://") {
host = strings.TrimPrefix(host, "http://")
}
if strings.HasPrefix(host, "https://") {
host = strings.TrimPrefix(host, "https://")
}
host := strings.TrimPrefix(strings.TrimPrefix(req.Host, "http://"), "https://")
// Remove port
if colonIndex := strings.Index(host, ":"); colonIndex != -1 {
host = host[:colonIndex]
@ -2550,7 +2544,7 @@ func (h *ConfigHandlers) HandleTestNodeConfig(w http.ResponseWriter, r *http.Req
latency := time.Since(startTime).Milliseconds()
testResult = map[string]interface{}{
"status": "success",
"message": fmt.Sprintf("Connected to PBS instance"),
"message": "Connected to PBS instance",
"latency": latency,
}
}

View file

@ -151,20 +151,18 @@ func (s *DockerMetadataStore) ReplaceAll(metadata map[string]*DockerMetadata) er
s.metadata = make(map[string]*DockerMetadata)
if metadata != nil {
for resourceID, meta := range metadata {
if meta == nil {
continue
}
clone := *meta
clone.ID = resourceID
// Ensure slice copy is not nil to allow JSON marshalling of empty tags
if clone.Tags == nil {
clone.Tags = []string{}
}
s.metadata[resourceID] = &clone
for resourceID, meta := range metadata {
if meta == nil {
continue
}
clone := *meta
clone.ID = resourceID
// Ensure slice copy is not nil to allow JSON marshalling of empty tags
if clone.Tags == nil {
clone.Tags = []string{}
}
s.metadata[resourceID] = &clone
}
return s.save()

View file

@ -180,20 +180,18 @@ func (s *GuestMetadataStore) ReplaceAll(metadata map[string]*GuestMetadata) erro
s.metadata = make(map[string]*GuestMetadata)
if metadata != nil {
for guestID, meta := range metadata {
if meta == nil {
continue
}
clone := *meta
clone.ID = guestID
// Ensure slice copy is not nil to allow JSON marshalling of empty tags
if clone.Tags == nil {
clone.Tags = []string{}
}
s.metadata[guestID] = &clone
for guestID, meta := range metadata {
if meta == nil {
continue
}
clone := *meta
clone.ID = guestID
// Ensure slice copy is not nil to allow JSON marshalling of empty tags
if clone.Tags == nil {
clone.Tags = []string{}
}
s.metadata[guestID] = &clone
}
return s.save()

View file

@ -409,7 +409,7 @@ func (pm *PollMetrics) SetBreakerState(instanceType, instance, state string, fai
retrySeconds := 0.0
if !retryAt.IsZero() {
retrySeconds = retryAt.Sub(time.Now()).Seconds()
retrySeconds = time.Until(retryAt).Seconds()
if retrySeconds < 0 {
retrySeconds = 0
}

View file

@ -2241,7 +2241,7 @@ func (n *NotificationManager) generatePayloadFromTemplateWithService(templateStr
if err := json.Unmarshal(buf.Bytes(), &jsonCheck); err != nil {
log.Error().
Err(err).
Str("payload", string(buf.Bytes())).
Str("payload", buf.String()).
Msg("Generated webhook payload is invalid JSON")
return nil, fmt.Errorf("template produced invalid JSON: %w", err)
}

View file

@ -285,7 +285,7 @@ func (s *Scanner) DiscoverServersWithCallbacks(ctx context.Context, subnet strin
} else if errors.Is(err, context.DeadlineExceeded) {
errType = "timeout"
// Provide user-friendly timeout message
errMsg = fmt.Sprintf("Scan timed out after 2 minutes - this is normal for large networks. Servers found in earlier phases are still available.")
errMsg = "Scan timed out after 2 minutes - this is normal for large networks. Servers found in earlier phases are still available."
}
result.AddError("extra_targets", errType, errMsg, "", 0)
if errors.Is(err, context.Canceled) {
@ -333,7 +333,7 @@ func (s *Scanner) DiscoverServersWithCallbacks(ctx context.Context, subnet strin
} else if errors.Is(err, context.DeadlineExceeded) {
errType = "timeout"
// Provide user-friendly timeout message
errMsg = fmt.Sprintf("Scan timed out after 2 minutes - this is normal for large networks. Servers found in earlier phases are still available.")
errMsg = "Scan timed out after 2 minutes - this is normal for large networks. Servers found in earlier phases are still available."
}
result.AddError(phase.Name, errType, errMsg, "", 0)
if errors.Is(err, context.Canceled) {
@ -781,9 +781,7 @@ func clonePhase(phase envdetect.SubnetPhase) envdetect.SubnetPhase {
cloned := phase
if phase.Subnets != nil {
cloned.Subnets = make([]net.IPNet, len(phase.Subnets))
for i, subnet := range phase.Subnets {
cloned.Subnets[i] = subnet
}
copy(cloned.Subnets, phase.Subnets)
}
return cloned
}