forked from Mirrors/jsonapi
avoid variable name collision
This commit is contained in:
parent
f4c5ee491c
commit
c6b352483c
21
response.go
21
response.go
|
@ -35,7 +35,7 @@ func MarshalJsonApiPayload(model interface{}) (*JsonApiPayload, error) {
|
||||||
func visitModelNode(model interface{}) (*JsonApiNode, []*JsonApiNode, error) {
|
func visitModelNode(model interface{}) (*JsonApiNode, []*JsonApiNode, error) {
|
||||||
node := new(JsonApiNode)
|
node := new(JsonApiNode)
|
||||||
|
|
||||||
var err error
|
var er error
|
||||||
var included []*JsonApiNode
|
var included []*JsonApiNode
|
||||||
|
|
||||||
modelType := reflect.TypeOf(model).Elem()
|
modelType := reflect.TypeOf(model).Elem()
|
||||||
|
@ -60,7 +60,8 @@ func visitModelNode(model interface{}) (*JsonApiNode, []*JsonApiNode, error) {
|
||||||
node.Id = fmt.Sprintf("%v", fieldValue.Interface())
|
node.Id = fmt.Sprintf("%v", fieldValue.Interface())
|
||||||
node.Type = args[1]
|
node.Type = args[1]
|
||||||
} else {
|
} 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" {
|
} else if annotation == "attr" {
|
||||||
if node.Attributes == nil {
|
if node.Attributes == nil {
|
||||||
|
@ -76,7 +77,8 @@ func visitModelNode(model interface{}) (*JsonApiNode, []*JsonApiNode, error) {
|
||||||
node.Attributes[args[1]] = fieldValue.Interface()
|
node.Attributes[args[1]] = fieldValue.Interface()
|
||||||
}
|
}
|
||||||
} else {
|
} 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" {
|
} else if annotation == "relation" {
|
||||||
|
|
||||||
|
@ -111,7 +113,8 @@ func visitModelNode(model interface{}) (*JsonApiNode, []*JsonApiNode, error) {
|
||||||
node.Relationships[k] = shallowNodes
|
node.Relationships[k] = shallowNodes
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = err
|
er = err
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
relationship, _, err := visitModelNode(fieldValue.Interface())
|
relationship, _, err := visitModelNode(fieldValue.Interface())
|
||||||
|
@ -123,20 +126,22 @@ func visitModelNode(model interface{}) (*JsonApiNode, []*JsonApiNode, error) {
|
||||||
|
|
||||||
node.Relationships[args[1]] = &shallowNode
|
node.Relationships[args[1]] = &shallowNode
|
||||||
} else {
|
} else {
|
||||||
err = err
|
er = err
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} 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
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if er != nil {
|
||||||
return nil, nil, err
|
return nil, nil, er
|
||||||
}
|
}
|
||||||
|
|
||||||
return node, included, nil
|
return node, included, nil
|
||||||
|
|
Loading…
Reference in New Issue