(dest interface{}, inter interface{}, v *StructListValidation)
| 389 | } |
| 390 | |
| 391 | func StructList(dest interface{}, inter interface{}, v *StructListValidation) (interface{}, []error) { |
| 392 | if inter == nil { |
| 393 | if v.TreatNullAsEmpty { |
| 394 | inter = make([]interface{}, 0) |
| 395 | } else { |
| 396 | if !v.AllowExplicitNull { |
| 397 | return nil, []error{ErrorCannotBeEmptyOrNull(v.Required)} |
| 398 | } |
| 399 | return nil, nil |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | interSlice, ok := cast.InterfaceToInterfaceSlice(inter) |
| 404 | if !ok { |
| 405 | return nil, []error{ErrorInvalidPrimitiveType(inter, PrimTypeList)} |
| 406 | } |
| 407 | |
| 408 | if v.MinLength != 0 { |
| 409 | if len(interSlice) < v.MinLength { |
| 410 | return nil, []error{ErrorTooFewElements(v.MinLength)} |
| 411 | } |
| 412 | } |
| 413 | if v.MaxLength != 0 { |
| 414 | if len(interSlice) > v.MaxLength { |
| 415 | return nil, []error{ErrorTooManyElements(v.MaxLength)} |
| 416 | } |
| 417 | } |
| 418 | for _, invalidLength := range v.InvalidLengths { |
| 419 | if len(interSlice) == invalidLength { |
| 420 | return nil, []error{ErrorWrongNumberOfElements(v.InvalidLengths)} |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | errs := []error{} |
| 425 | for i, interItem := range interSlice { |
| 426 | val := reflect.New(reflect.ValueOf(dest).Type().Elem().Elem()).Interface() |
| 427 | subErrs := Struct(val, interItem, v.StructValidation) |
| 428 | var ok bool |
| 429 | if errs, ok = errors.AddErrors(errs, subErrs, s.Index(i)); ok { |
| 430 | if v.ShortCircuit { |
| 431 | return nil, errs |
| 432 | } |
| 433 | continue |
| 434 | } |
| 435 | if interItem == nil { |
| 436 | val = nil // If the object was nil, set val to nil rather than a pointer to the initialized zero value |
| 437 | } |
| 438 | dest = appendVal(dest, val) |
| 439 | } |
| 440 | |
| 441 | return dest, errs |
| 442 | } |
| 443 | |
| 444 | func InterfaceStruct(inter interface{}, v *InterfaceStructValidation) (interface{}, []error) { |
| 445 | if inter == nil { |
no test coverage detected