From c6b352483c354b0a59532e0137544446e7a6cb67 Mon Sep 17 00:00:00 2001 From: Sam Woodard Date: Mon, 6 Jul 2015 14:39:24 -0700 Subject: [PATCH] avoid variable name collision --- response.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/response.go b/response.go index bb8f5f6..b2be5f1 100644 --- a/response.go +++ b/response.go @@ -35,7 +35,7 @@ func MarshalJsonApiPayload(model interface{}) (*JsonApiPayload, error) { func visitModelNode(model interface{}) (*JsonApiNode, []*JsonApiNode, error) { node := new(JsonApiNode) - var err error + var er error var included []*JsonApiNode modelType := reflect.TypeOf(model).Elem() @@ -60,7 +60,8 @@ func visitModelNode(model interface{}) (*JsonApiNode, []*JsonApiNode, error) { node.Id = fmt.Sprintf("%v", fieldValue.Interface()) node.Type = args[1] } else { - err = errors.New("'type' as second argument required for 'primary'") + er = errors.New("'type' as second argument required for 'primary'") + return false } } else if annotation == "attr" { if node.Attributes == nil { @@ -76,7 +77,8 @@ func visitModelNode(model interface{}) (*JsonApiNode, []*JsonApiNode, error) { node.Attributes[args[1]] = fieldValue.Interface() } } else { - err = errors.New("'type' as second argument required for 'primary'") + er = errors.New("'type' as second argument required for 'primary'") + return false } } else if annotation == "relation" { @@ -111,7 +113,8 @@ func visitModelNode(model interface{}) (*JsonApiNode, []*JsonApiNode, error) { node.Relationships[k] = shallowNodes } } else { - err = err + er = err + return false } } else { relationship, _, err := visitModelNode(fieldValue.Interface()) @@ -123,20 +126,22 @@ func visitModelNode(model interface{}) (*JsonApiNode, []*JsonApiNode, error) { node.Relationships[args[1]] = &shallowNode } else { - err = err + er = err + return false } } } else { - err = errors.New(fmt.Sprintf("Unsupported jsonapi tag annotation, %s", annotation)) + er = errors.New(fmt.Sprintf("Unsupported jsonapi tag annotation, %s", annotation)) + return false } } return false }) - if err != nil { - return nil, nil, err + if er != nil { + return nil, nil, er } return node, included, nil