ArrayValueFromString convert string to array of sepecified item data type we can support json formatted string like: string array: "[\"11\",\"12\",\"13\"]" integer array: "[11,12,13]" string array of uuid: "[\"1e88a975-3d26-4277-ace9-bea91b072977\",\"1e88a975-3d26-4277-ace9-bea91b072978\",\"1e88a975
(value string, dataType DataType)
| 583 | // we can also support comma delimited string value as long as the item not contain comma |
| 584 | // "11,12,13" |
| 585 | func ArrayValueFromString(value string, dataType DataType) (interface{}, error) { |
| 586 | if len(value) == 0 || value == "null" { |
| 587 | return nil, nil |
| 588 | } |
| 589 | value = strings.TrimSpace(value) |
| 590 | var arrVal []interface{} |
| 591 | if strings.HasPrefix(value, "[") { |
| 592 | arrVal = make([]interface{}, 0) |
| 593 | if err := json.Unmarshal([]byte(value), &arrVal); err != nil { |
| 594 | return nil, err |
| 595 | } |
| 596 | } else { |
| 597 | val := strings.Split(value, ",") |
| 598 | arrVal = make([]interface{}, len(val)) |
| 599 | for i, item := range val { |
| 600 | if len(item) == 0 || item == "null" { |
| 601 | arrVal[i] = nil |
| 602 | } else { |
| 603 | arrVal[i] = item |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | return ConvertToArrayValue(dataType, arrVal) |
| 608 | } |
no test coverage detected