(inter interface{}, v *InterfaceStructValidation)
| 442 | } |
| 443 | |
| 444 | func InterfaceStruct(inter interface{}, v *InterfaceStructValidation) (interface{}, []error) { |
| 445 | if inter == nil { |
| 446 | if v.TreatNullAsEmpty { |
| 447 | inter = make(map[interface{}]interface{}, 0) |
| 448 | } else { |
| 449 | if !v.AllowExplicitNull { |
| 450 | return nil, []error{ErrorCannotBeEmptyOrNull(v.Required)} |
| 451 | } |
| 452 | return nil, nil |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | interMap, ok := cast.InterfaceToStrInterfaceMap(inter) |
| 457 | if !ok { |
| 458 | return nil, []error{ErrorInvalidPrimitiveType(inter, PrimTypeMap)} |
| 459 | } |
| 460 | |
| 461 | var validTypeStrs []string |
| 462 | if v.InterfaceStructTypes != nil { |
| 463 | for typeStr := range v.InterfaceStructTypes { |
| 464 | validTypeStrs = append(validTypeStrs, typeStr) |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | typeStrValidation := &StringValidation{ |
| 469 | Required: true, |
| 470 | AllowedValues: validTypeStrs, |
| 471 | } |
| 472 | |
| 473 | typeStr, err := StringFromInterfaceMap(v.TypeKey, interMap, typeStrValidation) |
| 474 | if err != nil { |
| 475 | return nil, []error{err} |
| 476 | } |
| 477 | var typeObj interface{} |
| 478 | if v.Parser != nil { |
| 479 | typeObj, err = v.Parser(typeStr) |
| 480 | if err != nil { |
| 481 | return nil, []error{errors.Wrap(err, v.TypeKey)} |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | var typeFieldValidation *StructFieldValidation |
| 486 | if v.TypeStructField == "" { |
| 487 | typeFieldValidation = &StructFieldValidation{ |
| 488 | Key: v.TypeKey, |
| 489 | Nil: true, |
| 490 | } |
| 491 | } else { |
| 492 | typeFieldValidation = &StructFieldValidation{ |
| 493 | Key: v.TypeKey, |
| 494 | StructField: v.TypeStructField, |
| 495 | StringValidation: typeStrValidation, |
| 496 | Parser: v.Parser, |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | var structType *InterfaceStructType |
| 501 | if v.InterfaceStructTypes != nil { |
no test coverage detected