Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion healthcheck/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions jsonapi/control_uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions jsonapi/message_with_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion jsonapi/n4tosrv6/backbone_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
17 changes: 9 additions & 8 deletions jsonapi_test/message_with_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,42 @@ package jsonapi_test
import (
"bytes"
"encoding/json"
"fmt"
"errors"
"testing"

"github.com/nextmn/json-api/jsonapi"
)

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")
}

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) {
t.Errorf("Result of marshaling MessageWithError to json is incorrect")
}

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)
}
}
Loading