@@ -140,7 +140,6 @@ func UnmarshalManyPayload(in io.Reader, t reflect.Type) ([]interface{}, error) {
140140}
141141
142142func unmarshalNode (data * Node , model reflect.Value , included * map [string ]* Node ) (err error ) {
143-
144143 defer func () {
145144 if r := recover (); r != nil {
146145 err = fmt .Errorf ("data is not a jsonapi representation of '%v'" , model .Type ())
@@ -386,8 +385,11 @@ func assign(field, value reflect.Value) {
386385 }
387386}
388387
389- func unmarshalAttribute (attribute interface {}, args []string , structField reflect.StructField , fieldValue reflect.Value ) (value reflect.Value , err error ) {
390-
388+ func unmarshalAttribute (
389+ attribute interface {},
390+ args []string ,
391+ structField reflect.StructField ,
392+ fieldValue reflect.Value ) (value reflect.Value , err error ) {
391393 value = reflect .ValueOf (attribute )
392394 fieldType := structField .Type
393395
@@ -398,7 +400,8 @@ func unmarshalAttribute(attribute interface{}, args []string, structField reflec
398400 }
399401
400402 // Handle field of type time.Time
401- if fieldValue .Type () == reflect .TypeOf (time.Time {}) || fieldValue .Type () == reflect .TypeOf (new (time.Time )) {
403+ if fieldValue .Type () == reflect .TypeOf (time.Time {}) ||
404+ fieldValue .Type () == reflect .TypeOf (new (time.Time )) {
402405 value , err = handleTime (attribute , args , fieldType , fieldValue )
403406 return
404407 }
@@ -410,7 +413,8 @@ func unmarshalAttribute(attribute interface{}, args []string, structField reflec
410413 }
411414
412415 // Handle field containing slice of structs
413- if fieldValue .Type ().Kind () == reflect .Slice && reflect .TypeOf (fieldValue .Interface ()).Elem ().Kind () == reflect .Struct {
416+ if fieldValue .Type ().Kind () == reflect .Slice &&
417+ reflect .TypeOf (fieldValue .Interface ()).Elem ().Kind () == reflect .Struct {
414418 value , err = handleStructSlice (attribute , args , fieldType , fieldValue )
415419 return
416420 }
@@ -436,7 +440,11 @@ func unmarshalAttribute(attribute interface{}, args []string, structField reflec
436440 return
437441}
438442
439- func handleStringSlice (attribute interface {}, args []string , fieldType reflect.Type , fieldValue reflect.Value ) (reflect.Value , error ) {
443+ func handleStringSlice (
444+ attribute interface {},
445+ args []string ,
446+ fieldType reflect.Type ,
447+ fieldValue reflect.Value ) (reflect.Value , error ) {
440448 v := reflect .ValueOf (attribute )
441449 values := make ([]string , v .Len ())
442450 for i := 0 ; i < v .Len (); i ++ {
@@ -446,8 +454,11 @@ func handleStringSlice(attribute interface{}, args []string, fieldType reflect.T
446454 return reflect .ValueOf (values ), nil
447455}
448456
449- func handleTime (attribute interface {}, args []string , fieldType reflect.Type , fieldValue reflect.Value ) (reflect.Value , error ) {
450-
457+ func handleTime (
458+ attribute interface {},
459+ args []string ,
460+ fieldType reflect.Type ,
461+ fieldValue reflect.Value ) (reflect.Value , error ) {
451462 var isIso8601 bool
452463 v := reflect .ValueOf (attribute )
453464
@@ -494,7 +505,11 @@ func handleTime(attribute interface{}, args []string, fieldType reflect.Type, fi
494505 return reflect .ValueOf (t ), nil
495506}
496507
497- func handleNumeric (attribute interface {}, args []string , fieldType reflect.Type , fieldValue reflect.Value ) (reflect.Value , error ) {
508+ func handleNumeric (
509+ attribute interface {},
510+ args []string ,
511+ fieldType reflect.Type ,
512+ fieldValue reflect.Value ) (reflect.Value , error ) {
498513 v := reflect .ValueOf (attribute )
499514 floatValue := v .Interface ().(float64 )
500515
@@ -551,7 +566,12 @@ func handleNumeric(attribute interface{}, args []string, fieldType reflect.Type,
551566 return numericValue , nil
552567}
553568
554- func handlePointer (attribute interface {}, args []string , fieldType reflect.Type , fieldValue reflect.Value , structField reflect.StructField ) (reflect.Value , error ) {
569+ func handlePointer (
570+ attribute interface {},
571+ args []string ,
572+ fieldType reflect.Type ,
573+ fieldValue reflect.Value ,
574+ structField reflect.StructField ) (reflect.Value , error ) {
555575 t := fieldValue .Type ()
556576 var concreteVal reflect.Value
557577
@@ -560,50 +580,55 @@ func handlePointer(attribute interface{}, args []string, fieldType reflect.Type,
560580 concreteVal = reflect .ValueOf (& cVal )
561581 case bool :
562582 concreteVal = reflect .ValueOf (& cVal )
563- case complex64 :
564- concreteVal = reflect .ValueOf (& cVal )
565- case complex128 :
566- concreteVal = reflect .ValueOf (& cVal )
567- case uintptr :
583+ case complex64 , complex128 , uintptr :
568584 concreteVal = reflect .ValueOf (& cVal )
569585 case map [string ]interface {}:
570586 var err error
571587 concreteVal , err = handleStruct (attribute , args , fieldType , fieldValue )
572588 if err != nil {
573- return reflect.Value {}, newErrUnsupportedPtrType (reflect .ValueOf (attribute ), fieldType , structField )
589+ return reflect.Value {}, newErrUnsupportedPtrType (
590+ reflect .ValueOf (attribute ), fieldType , structField )
574591 }
575592 return concreteVal .Elem (), err
576593 default :
577- return reflect.Value {}, newErrUnsupportedPtrType (reflect .ValueOf (attribute ), fieldType , structField )
594+ return reflect.Value {}, newErrUnsupportedPtrType (
595+ reflect .ValueOf (attribute ), fieldType , structField )
578596 }
579597
580598 if t != concreteVal .Type () {
581- return reflect.Value {}, newErrUnsupportedPtrType (reflect .ValueOf (attribute ), fieldType , structField )
599+ return reflect.Value {}, newErrUnsupportedPtrType (
600+ reflect .ValueOf (attribute ), fieldType , structField )
582601 }
583602
584603 return concreteVal , nil
585604}
586605
587- func handleStruct (attribute interface {}, args []string , fieldType reflect.Type , fieldValue reflect.Value ) (reflect.Value , error ) {
606+ func handleStruct (
607+ attribute interface {},
608+ args []string ,
609+ fieldType reflect.Type ,
610+ fieldValue reflect.Value ) (reflect.Value , error ) {
588611 model := reflect .New (fieldValue .Type ())
589612
590- var er error
591-
592- data , er := json .Marshal (attribute )
593- if er != nil {
594- return model , er
613+ data , err := json .Marshal (attribute )
614+ if err != nil {
615+ return model , err
595616 }
596617
597- er = json .Unmarshal (data , model .Interface ())
618+ err = json .Unmarshal (data , model .Interface ())
598619
599- if er != nil {
600- return model , er
620+ if err != nil {
621+ return model , err
601622 }
602623
603- return model , er
624+ return model , err
604625}
605626
606- func handleStructSlice (attribute interface {}, args []string , fieldType reflect.Type , fieldValue reflect.Value ) (reflect.Value , error ) {
627+ func handleStructSlice (
628+ attribute interface {},
629+ args []string ,
630+ fieldType reflect.Type ,
631+ fieldValue reflect.Value ) (reflect.Value , error ) {
607632 models := reflect .New (fieldValue .Type ()).Elem ()
608633 dataMap := reflect .ValueOf (attribute ).Interface ().([]interface {})
609634 for _ , data := range dataMap {
0 commit comments