From 952f04a9f0d1c0bf9acd5b9f3c686333755c527a Mon Sep 17 00:00:00 2001 From: Louis Royer Date: Sun, 11 Jan 2026 17:19:14 +0100 Subject: [PATCH] Fix staticcheck SA1014, SA1006, and ST1005 --- healthcheck/healthcheck.go | 2 +- jsonapi/control_uri.go | 4 ++-- jsonapi/message_with_error.go | 6 +++--- jsonapi/n4tosrv6/backbone_ip.go | 2 +- jsonapi_test/message_with_error_test.go | 17 +++++++++-------- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/healthcheck/healthcheck.go b/healthcheck/healthcheck.go index a441567..b859c60 100644 --- a/healthcheck/healthcheck.go +++ b/healthcheck/healthcheck.go @@ -65,7 +65,7 @@ func (h *Healthcheck) Run(ctx context.Context) error { return err } if !status.Ready { - err := fmt.Errorf("Server is not ready") + err := fmt.Errorf("server is not ready") logrus.WithFields(logrus.Fields{"remote-server": h.url}).WithError(err).Info("Server is not ready") return err } diff --git a/jsonapi/control_uri.go b/jsonapi/control_uri.go index deee3a6..8f4a15a 100644 --- a/jsonapi/control_uri.go +++ b/jsonapi/control_uri.go @@ -30,10 +30,10 @@ func (u ControlURI) MarshalJSON() ([]byte, error) { func ParseControlURI(text string) (*ControlURI, error) { if len(text) == 0 { - return nil, fmt.Errorf("Control URI should not be empty.") + return nil, fmt.Errorf("control URI should not be empty") } if text[len(text)-1] == '/' { - return nil, fmt.Errorf("Control URI should not contains trailing slash.") + return nil, fmt.Errorf("control URI should not contains trailing slash") } if u, err := url.ParseRequestURI(text); err != nil { return nil, err diff --git a/jsonapi/message_with_error.go b/jsonapi/message_with_error.go index 6f636cf..822302f 100644 --- a/jsonapi/message_with_error.go +++ b/jsonapi/message_with_error.go @@ -17,18 +17,18 @@ type MessageWithError struct { func (u *MessageWithError) UnmarshalJSON(data []byte) error { a := make(map[string]string) - err := json.Unmarshal(data, a) + err := json.Unmarshal(data, &a) if err != nil { return err } msg, ok := a["message"] if !ok { - return fmt.Errorf("Missing key `message` while unmarshaling MessageWithError") + return fmt.Errorf("missing key `message` while unmarshaling MessageWithError") } u.Message = msg e, ok := a["error"] if !ok { - return fmt.Errorf("Missing key `error` while unmarshaling MessageWithError") + return fmt.Errorf("missing key `error` while unmarshaling MessageWithError") } u.Error = fmt.Errorf("%s", e) return nil diff --git a/jsonapi/n4tosrv6/backbone_ip.go b/jsonapi/n4tosrv6/backbone_ip.go index ac42358..9494228 100644 --- a/jsonapi/n4tosrv6/backbone_ip.go +++ b/jsonapi/n4tosrv6/backbone_ip.go @@ -19,7 +19,7 @@ func (b *BackboneIP) UnmarshalText(text []byte) error { return err } if !b.Addr.Is6() { - return fmt.Errorf("Backbone IP must be an IPv6 address") + return fmt.Errorf("backbone IP must be an IPv6 address") } return nil } diff --git a/jsonapi_test/message_with_error_test.go b/jsonapi_test/message_with_error_test.go index e9248be..306286c 100644 --- a/jsonapi_test/message_with_error_test.go +++ b/jsonapi_test/message_with_error_test.go @@ -8,7 +8,7 @@ package jsonapi_test import ( "bytes" "encoding/json" - "fmt" + "errors" "testing" "github.com/nextmn/json-api/jsonapi" @@ -16,12 +16,13 @@ import ( func TestMessageWithError(t *testing.T) { const ( - msg_test = "Example of message" - err_test = "Example of error" + msg_test = "Example of message" + err_test_msg = "example of error" ) + err_test := errors.New(err_test_msg) j2, err := json.Marshal(map[string]string{ "message": msg_test, - "error": err_test, + "error": err_test_msg, }) if err != nil { t.Fatalf("Could not marshal map to json") @@ -29,12 +30,12 @@ func TestMessageWithError(t *testing.T) { u := &jsonapi.MessageWithError{ Message: msg_test, - Error: fmt.Errorf(err_test), + Error: err_test, } j1, err := json.Marshal(u) if err != nil { - t.Errorf("Could not marshal MessageWithError to json") + t.Error("Could not marshal MessageWithError to json") } if !bytes.Equal(j1, j2) { @@ -42,7 +43,7 @@ func TestMessageWithError(t *testing.T) { } unm := &jsonapi.MessageWithError{} - if err := unm.UnmarshalJSON(j1); err == nil { - t.Errorf("Unmarshal of MessageWithError failed") + if err := unm.UnmarshalJSON(j1); err != nil { + t.Errorf("Unmarshal of MessageWithError failed: %s", err) } }