Skip to content

Commit 952f04a

Browse files
committed
Fix staticcheck SA1014, SA1006, and ST1005
1 parent 766ab3f commit 952f04a

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

healthcheck/healthcheck.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (h *Healthcheck) Run(ctx context.Context) error {
6565
return err
6666
}
6767
if !status.Ready {
68-
err := fmt.Errorf("Server is not ready")
68+
err := fmt.Errorf("server is not ready")
6969
logrus.WithFields(logrus.Fields{"remote-server": h.url}).WithError(err).Info("Server is not ready")
7070
return err
7171
}

jsonapi/control_uri.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ func (u ControlURI) MarshalJSON() ([]byte, error) {
3030

3131
func ParseControlURI(text string) (*ControlURI, error) {
3232
if len(text) == 0 {
33-
return nil, fmt.Errorf("Control URI should not be empty.")
33+
return nil, fmt.Errorf("control URI should not be empty")
3434
}
3535
if text[len(text)-1] == '/' {
36-
return nil, fmt.Errorf("Control URI should not contains trailing slash.")
36+
return nil, fmt.Errorf("control URI should not contains trailing slash")
3737
}
3838
if u, err := url.ParseRequestURI(text); err != nil {
3939
return nil, err

jsonapi/message_with_error.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ type MessageWithError struct {
1717

1818
func (u *MessageWithError) UnmarshalJSON(data []byte) error {
1919
a := make(map[string]string)
20-
err := json.Unmarshal(data, a)
20+
err := json.Unmarshal(data, &a)
2121
if err != nil {
2222
return err
2323
}
2424
msg, ok := a["message"]
2525
if !ok {
26-
return fmt.Errorf("Missing key `message` while unmarshaling MessageWithError")
26+
return fmt.Errorf("missing key `message` while unmarshaling MessageWithError")
2727
}
2828
u.Message = msg
2929
e, ok := a["error"]
3030
if !ok {
31-
return fmt.Errorf("Missing key `error` while unmarshaling MessageWithError")
31+
return fmt.Errorf("missing key `error` while unmarshaling MessageWithError")
3232
}
3333
u.Error = fmt.Errorf("%s", e)
3434
return nil

jsonapi/n4tosrv6/backbone_ip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (b *BackboneIP) UnmarshalText(text []byte) error {
1919
return err
2020
}
2121
if !b.Addr.Is6() {
22-
return fmt.Errorf("Backbone IP must be an IPv6 address")
22+
return fmt.Errorf("backbone IP must be an IPv6 address")
2323
}
2424
return nil
2525
}

jsonapi_test/message_with_error_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,42 @@ package jsonapi_test
88
import (
99
"bytes"
1010
"encoding/json"
11-
"fmt"
11+
"errors"
1212
"testing"
1313

1414
"github.com/nextmn/json-api/jsonapi"
1515
)
1616

1717
func TestMessageWithError(t *testing.T) {
1818
const (
19-
msg_test = "Example of message"
20-
err_test = "Example of error"
19+
msg_test = "Example of message"
20+
err_test_msg = "example of error"
2121
)
22+
err_test := errors.New(err_test_msg)
2223
j2, err := json.Marshal(map[string]string{
2324
"message": msg_test,
24-
"error": err_test,
25+
"error": err_test_msg,
2526
})
2627
if err != nil {
2728
t.Fatalf("Could not marshal map to json")
2829
}
2930

3031
u := &jsonapi.MessageWithError{
3132
Message: msg_test,
32-
Error: fmt.Errorf(err_test),
33+
Error: err_test,
3334
}
3435

3536
j1, err := json.Marshal(u)
3637
if err != nil {
37-
t.Errorf("Could not marshal MessageWithError to json")
38+
t.Error("Could not marshal MessageWithError to json")
3839
}
3940

4041
if !bytes.Equal(j1, j2) {
4142
t.Errorf("Result of marshaling MessageWithError to json is incorrect")
4243
}
4344

4445
unm := &jsonapi.MessageWithError{}
45-
if err := unm.UnmarshalJSON(j1); err == nil {
46-
t.Errorf("Unmarshal of MessageWithError failed")
46+
if err := unm.UnmarshalJSON(j1); err != nil {
47+
t.Errorf("Unmarshal of MessageWithError failed: %s", err)
4748
}
4849
}

0 commit comments

Comments
 (0)