Skip to content

Commit 6bf44fa

Browse files
committed
return function return value when is only err
1 parent 9246c91 commit 6bf44fa

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

errors.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ import (
1212
// http://jsonapi.org/format/#document-top-level
1313
// and here: http://jsonapi.org/format/#error-objects.
1414
func MarshalErrors(w io.Writer, errorObjects []*ErrorObject) error {
15-
if err := json.NewEncoder(w).Encode(&ErrorsPayload{Errors: errorObjects}); err != nil {
16-
return err
17-
}
18-
return nil
15+
return json.NewEncoder(w).Encode(&ErrorsPayload{Errors: errorObjects})
1916
}
2017

2118
// ErrorsPayload is a serializer struct for representing a valid JSON API errors payload.

response.go

+3-13
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ func MarshalPayload(w io.Writer, models interface{}) error {
6868
return err
6969
}
7070

71-
if err := json.NewEncoder(w).Encode(payload); err != nil {
72-
return err
73-
}
74-
return nil
71+
return json.NewEncoder(w).Encode(payload)
7572
}
7673

7774
// Marshal does the same as MarshalPayload except it just returns the payload
@@ -128,10 +125,7 @@ func MarshalPayloadWithoutIncluded(w io.Writer, model interface{}) error {
128125
}
129126
payload.clearIncluded()
130127

131-
if err := json.NewEncoder(w).Encode(payload); err != nil {
132-
return err
133-
}
134-
return nil
128+
return json.NewEncoder(w).Encode(payload)
135129
}
136130

137131
// marshalOne does the same as MarshalOnePayload except it just returns the
@@ -195,11 +189,7 @@ func MarshalOnePayloadEmbedded(w io.Writer, model interface{}) error {
195189

196190
payload := &OnePayload{Data: rootNode}
197191

198-
if err := json.NewEncoder(w).Encode(payload); err != nil {
199-
return err
200-
}
201-
202-
return nil
192+
return json.NewEncoder(w).Encode(payload)
203193
}
204194

205195
func visitModelNode(model interface{}, included *map[string]*Node,

0 commit comments

Comments
 (0)