remove arg len check since we already do it above

This commit is contained in:
Sam Woodard 2015-07-10 08:20:49 -07:00
parent a228611aa0
commit 84eed2060a
2 changed files with 49 additions and 68 deletions

View File

@ -55,7 +55,6 @@ func unmarshalJsonApiNode(data *JsonApiNode, model reflect.Value) error {
return false
}
if len(args) >= 2 {
if data.Type != args[1] {
er = errors.New("Trying to Unmarshal a type that does not match")
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")
return false
}
} else {
er = errors.New("'type' as second argument required for 'primary'")
return false
}
} else if annotation == "attr" {
attributes := data.Attributes
if attributes == nil {
return false
}
if len(args) >= 2 {
val := attributes[args[1]]
// next if the attribute was not included in the request
@ -119,9 +113,6 @@ func unmarshalJsonApiNode(data *JsonApiNode, model reflect.Value) error {
} else {
fieldValue.Set(reflect.ValueOf(val))
}
} else {
er = errors.New("Attribute key required as second arg")
}
} else if annotation == "relation" {
isSlice := fieldValue.Type().Kind() == reflect.Slice

View File

@ -109,19 +109,13 @@ func visitModelNode(model interface{}, sideload bool) (*JsonApiNode, []*JsonApiN
annotation := args[0]
if annotation == "primary" {
if len(args) >= 2 {
node.Id = fmt.Sprintf("%v", fieldValue.Interface())
node.Type = args[1]
} else {
er = errors.New("'type' as second argument required for 'primary'")
return false
}
} else if annotation == "attr" {
if node.Attributes == nil {
node.Attributes = make(map[string]interface{})
}
if len(args) >= 2 {
if fieldValue.Type() == reflect.TypeOf(time.Time{}) {
isZeroMethod := fieldValue.MethodByName("IsZero")
isZero := isZeroMethod.Call(make([]reflect.Value, 0))[0].Interface().(bool)
@ -135,10 +129,6 @@ func visitModelNode(model interface{}, sideload bool) (*JsonApiNode, []*JsonApiN
} else {
node.Attributes[args[1]] = fieldValue.Interface()
}
} else {
er = errors.New("'type' as second argument required for 'primary'")
return false
}
} else if annotation == "relation" {
isSlice := fieldValue.Type().Kind() == reflect.Slice