forked from Mirrors/jsonapi
remove arg len check since we already do it above
This commit is contained in:
parent
a228611aa0
commit
84eed2060a
|
@ -55,7 +55,6 @@ func unmarshalJsonApiNode(data *JsonApiNode, model reflect.Value) error {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) >= 2 {
|
|
||||||
if data.Type != args[1] {
|
if data.Type != args[1] {
|
||||||
er = errors.New("Trying to Unmarshal a type that does not match")
|
er = errors.New("Trying to Unmarshal a type that does not match")
|
||||||
return false
|
return false
|
||||||
|
@ -74,17 +73,12 @@ func unmarshalJsonApiNode(data *JsonApiNode, model reflect.Value) error {
|
||||||
er = errors.New("Unsuppored data type for primary key, not int or string")
|
er = errors.New("Unsuppored data type for primary key, not int or string")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
er = errors.New("'type' as second argument required for 'primary'")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
} else if annotation == "attr" {
|
} else if annotation == "attr" {
|
||||||
attributes := data.Attributes
|
attributes := data.Attributes
|
||||||
if attributes == nil {
|
if attributes == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) >= 2 {
|
|
||||||
val := attributes[args[1]]
|
val := attributes[args[1]]
|
||||||
|
|
||||||
// next if the attribute was not included in the request
|
// next if the attribute was not included in the request
|
||||||
|
@ -119,9 +113,6 @@ func unmarshalJsonApiNode(data *JsonApiNode, model reflect.Value) error {
|
||||||
} else {
|
} else {
|
||||||
fieldValue.Set(reflect.ValueOf(val))
|
fieldValue.Set(reflect.ValueOf(val))
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
er = errors.New("Attribute key required as second arg")
|
|
||||||
}
|
|
||||||
} else if annotation == "relation" {
|
} else if annotation == "relation" {
|
||||||
isSlice := fieldValue.Type().Kind() == reflect.Slice
|
isSlice := fieldValue.Type().Kind() == reflect.Slice
|
||||||
|
|
||||||
|
|
10
response.go
10
response.go
|
@ -109,19 +109,13 @@ func visitModelNode(model interface{}, sideload bool) (*JsonApiNode, []*JsonApiN
|
||||||
annotation := args[0]
|
annotation := args[0]
|
||||||
|
|
||||||
if annotation == "primary" {
|
if annotation == "primary" {
|
||||||
if len(args) >= 2 {
|
|
||||||
node.Id = fmt.Sprintf("%v", fieldValue.Interface())
|
node.Id = fmt.Sprintf("%v", fieldValue.Interface())
|
||||||
node.Type = args[1]
|
node.Type = args[1]
|
||||||
} else {
|
|
||||||
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 {
|
||||||
node.Attributes = make(map[string]interface{})
|
node.Attributes = make(map[string]interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) >= 2 {
|
|
||||||
if fieldValue.Type() == reflect.TypeOf(time.Time{}) {
|
if fieldValue.Type() == reflect.TypeOf(time.Time{}) {
|
||||||
isZeroMethod := fieldValue.MethodByName("IsZero")
|
isZeroMethod := fieldValue.MethodByName("IsZero")
|
||||||
isZero := isZeroMethod.Call(make([]reflect.Value, 0))[0].Interface().(bool)
|
isZero := isZeroMethod.Call(make([]reflect.Value, 0))[0].Interface().(bool)
|
||||||
|
@ -135,10 +129,6 @@ func visitModelNode(model interface{}, sideload bool) (*JsonApiNode, []*JsonApiN
|
||||||
} else {
|
} else {
|
||||||
node.Attributes[args[1]] = fieldValue.Interface()
|
node.Attributes[args[1]] = fieldValue.Interface()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
er = errors.New("'type' as second argument required for 'primary'")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
} else if annotation == "relation" {
|
} else if annotation == "relation" {
|
||||||
|
|
||||||
isSlice := fieldValue.Type().Kind() == reflect.Slice
|
isSlice := fieldValue.Type().Kind() == reflect.Slice
|
||||||
|
|
Loading…
Reference in New Issue