rename files, only initialize included if there are relationships

This commit is contained in:
Sam Woodard 2015-07-06 09:24:35 -07:00
parent e039cc4394
commit f8d5fbba3d
3 changed files with 16 additions and 12 deletions

12
node.go Normal file
View File

@ -0,0 +1,12 @@
package jsonapi
type JsonApiNodeWrapper struct {
Data *JsonApiNode `json:"data"`
}
type JsonApiNode struct {
Type string `json:"type"`
Id string `json:"id"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
Relationships map[string]interface{} `json:"realtionships,omitempty"`
}

View File

@ -7,17 +7,6 @@ import (
"strings"
)
type JsonApiNodeWrapper struct {
Data *JsonApiNode `json:"data"`
}
type JsonApiNode struct {
Type string `json:"type"`
Id string `json:"id"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
Relationships map[string]interface{} `json:"realtionships,omitempty"`
}
type JsonApiResponse struct {
Data *JsonApiNode `json:"data"`
Included []*JsonApiNode `json:"included,omitempty"`
@ -51,7 +40,7 @@ func visitModelNode(model interface{}) (*JsonApiNode, []*JsonApiNode, error) {
node := new(JsonApiNode)
var err error
included := make([]*JsonApiNode, 0)
var included []*JsonApiNode
modelType := reflect.TypeOf(model)
@ -86,6 +75,9 @@ func visitModelNode(model interface{}) (*JsonApiNode, []*JsonApiNode, error) {
if node.Relationships == nil {
node.Relationships = make(map[string]interface{})
}
if included == nil {
included = make([]*JsonApiNode, 0)
}
if fieldValue.Type().Kind() == reflect.Slice {
relationship, err := visitModelNodeRelationships(args[1], fieldValue)