From 1cb86c4ab7f0adfc853018f7743d16bd2e2c811b Mon Sep 17 00:00:00 2001 From: ProtoTess <32490978+0x524A@users.noreply.github.com> Date: Tue, 18 Nov 2025 17:55:43 +0000 Subject: [PATCH] feat: Add linter configuration and improve error handling in download functions --- .golangci.yml | 28 ++++++++++++++++++++++++++++ client.go | 4 ++-- cmd/onvif-cli/main.go | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..e3ad6fa --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,28 @@ +version: 2 + +linters: + enable: + - errcheck + - govet + - staticcheck + - unused + +issues: + exclude-rules: + - path: _test\.go + linters: + - errcheck + - path: examples/ + linters: + - errcheck + - unused + +run: + timeout: 5m + tests: true + +output: + format: colored-line-number + print-issued-lines: true + print-linter-name: true + sort-results: true diff --git a/client.go b/client.go index de8909a..00ea915 100644 --- a/client.go +++ b/client.go @@ -249,7 +249,7 @@ func (c *Client) downloadWithBasicAuth(ctx context.Context, downloadURL string) if err != nil { return nil, fmt.Errorf("download request failed: %w", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { bodyPreview, _ := io.ReadAll(resp.Body) @@ -328,7 +328,7 @@ func (c *Client) downloadWithDigestAuth(ctx context.Context, downloadURL string) if err != nil { return nil, fmt.Errorf("digest auth request failed: %w", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { bodyPreview, _ := io.ReadAll(resp.Body) diff --git a/cmd/onvif-cli/main.go b/cmd/onvif-cli/main.go index b748449..6a324b5 100644 --- a/cmd/onvif-cli/main.go +++ b/cmd/onvif-cli/main.go @@ -610,7 +610,7 @@ func (c *CLI) tryRTSPConnection(streamURI string) map[string]interface{} { // Try to connect conn, err := net.DialTimeout("tcp", hostPort, 3*time.Second) if err == nil { - conn.Close() + _ = conn.Close() // Ignore error on close for connectivity check details["reachable"] = true details["port"] = strings.Split(hostPort, ":")[1] return details