From 6bf44faa3c68876902613e74c130fac4880685a8 Mon Sep 17 00:00:00 2001 From: Sam Woodard Date: Tue, 16 Oct 2018 07:33:23 -0700 Subject: [PATCH] return function return value when is only err --- errors.go | 5 +---- response.go | 16 +++------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/errors.go b/errors.go index ed7fa9f..798fed0 100644 --- a/errors.go +++ b/errors.go @@ -12,10 +12,7 @@ import ( // http://jsonapi.org/format/#document-top-level // and here: http://jsonapi.org/format/#error-objects. func MarshalErrors(w io.Writer, errorObjects []*ErrorObject) error { - if err := json.NewEncoder(w).Encode(&ErrorsPayload{Errors: errorObjects}); err != nil { - return err - } - return nil + return json.NewEncoder(w).Encode(&ErrorsPayload{Errors: errorObjects}) } // ErrorsPayload is a serializer struct for representing a valid JSON API errors payload. diff --git a/response.go b/response.go index e8e85fa..bee7e8f 100644 --- a/response.go +++ b/response.go @@ -68,10 +68,7 @@ func MarshalPayload(w io.Writer, models interface{}) error { return err } - if err := json.NewEncoder(w).Encode(payload); err != nil { - return err - } - return nil + return json.NewEncoder(w).Encode(payload) } // Marshal does the same as MarshalPayload except it just returns the payload @@ -128,10 +125,7 @@ func MarshalPayloadWithoutIncluded(w io.Writer, model interface{}) error { } payload.clearIncluded() - if err := json.NewEncoder(w).Encode(payload); err != nil { - return err - } - return nil + return json.NewEncoder(w).Encode(payload) } // marshalOne does the same as MarshalOnePayload except it just returns the @@ -195,11 +189,7 @@ func MarshalOnePayloadEmbedded(w io.Writer, model interface{}) error { payload := &OnePayload{Data: rootNode} - if err := json.NewEncoder(w).Encode(payload); err != nil { - return err - } - - return nil + return json.NewEncoder(w).Encode(payload) } func visitModelNode(model interface{}, included *map[string]*Node,