chore: enhance golangci-lint configuration and clean up error handling
- Added new linters for the examples directory to improve code quality checks. - Updated output formatting to direct lint results to stdout for better visibility. - Cleaned up comments related to error handling in various files for clarity and consistency.
This commit is contained in:
+17
-1
@@ -98,8 +98,24 @@ linters:
|
|||||||
- path: cmd/
|
- path: cmd/
|
||||||
linters:
|
linters:
|
||||||
- dupl
|
- dupl
|
||||||
|
|
||||||
|
- path: examples/
|
||||||
|
linters:
|
||||||
|
- errcheck
|
||||||
|
- err113
|
||||||
|
- funlen
|
||||||
|
- gocognit
|
||||||
|
- gocritic
|
||||||
|
- gocyclo
|
||||||
|
- godot
|
||||||
|
- gosec
|
||||||
|
- mnd
|
||||||
|
- nlreturn
|
||||||
|
- noctx
|
||||||
|
- unused
|
||||||
|
- wrapcheck
|
||||||
|
|
||||||
output:
|
output:
|
||||||
formats:
|
formats:
|
||||||
text:
|
text:
|
||||||
print-linter-name: true
|
path: stdout
|
||||||
|
|||||||
@@ -286,12 +286,10 @@ func (c *Client) downloadWithBasicAuth(ctx context.Context, downloadURL string)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("download request failed: %w", err)
|
return nil, fmt.Errorf("download request failed: %w", err)
|
||||||
}
|
}
|
||||||
//nolint:errcheck // Close error in defer is intentionally ignored
|
|
||||||
defer func() { _ = resp.Body.Close() }()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
//nolint:errcheck // Error response body preview - ignore read errors
|
bodyPreview, _ := io.ReadAll(resp.Body) //nolint:errcheck // Error preview - ignore read errors
|
||||||
bodyPreview, _ := io.ReadAll(resp.Body)
|
|
||||||
bodyStr := string(bodyPreview)
|
bodyStr := string(bodyPreview)
|
||||||
const maxBodyPreview = 200
|
const maxBodyPreview = 200
|
||||||
if len(bodyStr) > maxBodyPreview {
|
if len(bodyStr) > maxBodyPreview {
|
||||||
@@ -365,12 +363,10 @@ func (c *Client) downloadWithDigestAuth(ctx context.Context, downloadURL string)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("digest auth request failed: %w", err)
|
return nil, fmt.Errorf("digest auth request failed: %w", err)
|
||||||
}
|
}
|
||||||
//nolint:errcheck // Close error in defer is intentionally ignored
|
|
||||||
defer func() { _ = resp.Body.Close() }()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
//nolint:errcheck // Error response body preview - ignore read errors
|
bodyPreview, _ := io.ReadAll(resp.Body) //nolint:errcheck // Error preview - ignore read errors
|
||||||
bodyPreview, _ := io.ReadAll(resp.Body)
|
|
||||||
bodyStr := string(bodyPreview)
|
bodyStr := string(bodyPreview)
|
||||||
const maxBodyPreview = 200
|
const maxBodyPreview = 200
|
||||||
if len(bodyStr) > maxBodyPreview {
|
if len(bodyStr) > maxBodyPreview {
|
||||||
|
|||||||
@@ -220,12 +220,10 @@ func main() {
|
|||||||
log.Fatalf("Failed to create output file: %v", err)
|
log.Fatalf("Failed to create output file: %v", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
//nolint:errcheck // Close error is not critical, file is already written
|
|
||||||
_ = f.Close()
|
_ = f.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := tmpl.Execute(f, testData); err != nil {
|
if err := tmpl.Execute(f, testData); err != nil {
|
||||||
//nolint:errcheck // Close error is not critical before fatal exit
|
|
||||||
_ = f.Close()
|
_ = f.Close()
|
||||||
//nolint:gocritic // Fatalf exits, defer won't run - this is acceptable
|
//nolint:gocritic // Fatalf exits, defer won't run - this is acceptable
|
||||||
log.Fatalf("Failed to execute template: %v", err)
|
log.Fatalf("Failed to execute template: %v", err)
|
||||||
|
|||||||
@@ -220,17 +220,17 @@ type ImageInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// formatBytes converts bytes to human-readable format.
|
// formatBytes converts bytes to human-readable format.
|
||||||
func formatBytes(bytes int64) string {
|
func formatBytes(byteCount int64) string {
|
||||||
if bytes < bufferSize1024 {
|
if byteCount < bufferSize1024 {
|
||||||
return fmt.Sprintf("%d B", bytes)
|
return fmt.Sprintf("%d B", byteCount)
|
||||||
}
|
}
|
||||||
const kbSize = 1024
|
const kbSize = 1024
|
||||||
const mbSize = 1024 * 1024
|
const mbSize = 1024 * 1024
|
||||||
if bytes < mbSize {
|
if byteCount < mbSize {
|
||||||
return fmt.Sprintf("%.1f KB", float64(bytes)/kbSize)
|
return fmt.Sprintf("%.1f KB", float64(byteCount)/kbSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%.1f MB", float64(bytes)/mbSize)
|
return fmt.Sprintf("%.1f MB", float64(byteCount)/mbSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateASCIIHighQuality creates a high-quality ASCII representation.
|
// CreateASCIIHighQuality creates a high-quality ASCII representation.
|
||||||
|
|||||||
@@ -690,7 +690,6 @@ func (c *CLI) tryRTSPConnection(streamURI string) map[string]interface{} {
|
|||||||
// Try to connect
|
// Try to connect
|
||||||
conn, err := net.DialTimeout("tcp", hostPort, maxRetries*time.Second)
|
conn, err := net.DialTimeout("tcp", hostPort, maxRetries*time.Second)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
//nolint:errcheck // Close error is not critical for connectivity check
|
|
||||||
_ = conn.Close()
|
_ = conn.Close()
|
||||||
details["reachable"] = true
|
details["reachable"] = true
|
||||||
details["port"] = strings.Split(hostPort, ":")[1]
|
details["port"] = strings.Split(hostPort, ":")[1]
|
||||||
|
|||||||
@@ -1102,21 +1102,18 @@ func createTarGz(sourceDir, archivePath string) error {
|
|||||||
return fmt.Errorf("failed to create archive file: %w", err)
|
return fmt.Errorf("failed to create archive file: %w", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
//nolint:errcheck // Close error is not critical for cleanup
|
|
||||||
_ = archiveFile.Close()
|
_ = archiveFile.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Create gzip writer
|
// Create gzip writer
|
||||||
gzWriter := gzip.NewWriter(archiveFile)
|
gzWriter := gzip.NewWriter(archiveFile)
|
||||||
defer func() {
|
defer func() {
|
||||||
//nolint:errcheck // Close error is not critical for cleanup
|
|
||||||
_ = gzWriter.Close()
|
_ = gzWriter.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Create tar writer
|
// Create tar writer
|
||||||
tarWriter := tar.NewWriter(gzWriter)
|
tarWriter := tar.NewWriter(gzWriter)
|
||||||
defer func() {
|
defer func() {
|
||||||
//nolint:errcheck // Close error is not critical for cleanup
|
|
||||||
_ = tarWriter.Close()
|
_ = tarWriter.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -1156,7 +1153,6 @@ func createTarGz(sourceDir, archivePath string) error {
|
|||||||
return fmt.Errorf("failed to open file: %w", err)
|
return fmt.Errorf("failed to open file: %w", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
//nolint:errcheck // Close error is not critical for cleanup
|
|
||||||
_ = file.Close()
|
_ = file.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ func DiscoverWithOptions(ctx context.Context, timeout time.Duration, opts *Disco
|
|||||||
return nil, fmt.Errorf("failed to listen on multicast address: %w", err)
|
return nil, fmt.Errorf("failed to listen on multicast address: %w", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
//nolint:errcheck // Close error is not critical for cleanup
|
|
||||||
_ = conn.Close()
|
_ = conn.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
@@ -147,7 +147,6 @@ func (c *Client) Call(ctx context.Context, endpoint, action string, request, res
|
|||||||
return fmt.Errorf("failed to send HTTP request: %w", err)
|
return fmt.Errorf("failed to send HTTP request: %w", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
//nolint:errcheck // Close error is not critical for cleanup
|
|
||||||
_ = resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//nolint:errcheck // Close error is not critical for cleanup
|
|
||||||
_ = r.Body.Close()
|
_ = r.Body.Close()
|
||||||
|
|
||||||
// Extract action from raw XML first (before parsing)
|
// Extract action from raw XML first (before parsing)
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ func LoadCaptureFromArchive(archivePath string) (*CameraCapture, error) {
|
|||||||
return nil, fmt.Errorf("failed to open archive: %w", err)
|
return nil, fmt.Errorf("failed to open archive: %w", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
//nolint:errcheck // Close error is not critical for cleanup
|
|
||||||
_ = file.Close()
|
_ = file.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -49,7 +48,6 @@ func LoadCaptureFromArchive(archivePath string) (*CameraCapture, error) {
|
|||||||
return nil, fmt.Errorf("failed to create gzip reader: %w", err)
|
return nil, fmt.Errorf("failed to create gzip reader: %w", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
//nolint:errcheck // Close error is not critical for cleanup
|
|
||||||
_ = gzr.Close()
|
_ = gzr.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user