Refactor golangci-lint configuration and improve error handling
- Updated .golangci.yml to enable default linters and refine suppression rules, enhancing code quality visibility. - Improved error handling in cmd/root.go by explicitly discarding low-value error messages during fatal exits for consistency with errcheck posture. - Added best-effort error handling in various locations across the codebase, ensuring that non-critical errors are logged without affecting overall functionality. - Introduced a new writeMetricsText function to streamline metrics output, improving code clarity and maintainability.
This commit is contained in:
+2
-3
@@ -135,6 +135,8 @@ func SaveDefaultConfig(configPath string) error {
|
||||
return fmt.Errorf("failed to marshal default config: %w", err)
|
||||
}
|
||||
|
||||
// #nosec G306 -- 0644 appropriate for generated default config.yaml (user-editable, no secrets/credentials; only sizes/URLs/paths)
|
||||
// G304 on ReadFile below is similar (trusted user config path)
|
||||
if err := os.WriteFile(configPath, data, 0644); err != nil {
|
||||
return fmt.Errorf("failed to write default config file: %w", err)
|
||||
}
|
||||
@@ -207,9 +209,6 @@ func (c Config) Validate() error {
|
||||
return fmt.Errorf("invalid trusted_proxies CIDR: %s", p)
|
||||
}
|
||||
}
|
||||
if c.MaxConcurrentRequests < 0 || c.MaxRequestsPerClient < 0 { // already covered above but explicit for the concurrency knobs
|
||||
// covered by earlier checks
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user