(val interface{})
| 377 | } |
| 378 | |
| 379 | func UserStrs(val interface{}) []string { |
| 380 | if val == nil { |
| 381 | return nil |
| 382 | } |
| 383 | |
| 384 | if reflect.TypeOf(val).Kind() != reflect.Slice { |
| 385 | val = []interface{}{val} |
| 386 | } |
| 387 | |
| 388 | inVal := reflect.ValueOf(val) |
| 389 | if inVal.IsNil() { |
| 390 | return nil |
| 391 | } |
| 392 | |
| 393 | // Handle case where caller passed in a nested slice |
| 394 | if inVal.Len() == 1 { |
| 395 | if inVal.Index(0).Kind() == reflect.Slice { |
| 396 | inVal = inVal.Index(0) |
| 397 | } else if inVal.Index(0).Kind() == reflect.Interface { // Handle case where input is e.g. []interface{[]string{"test"}} |
| 398 | firstElementVal := reflect.ValueOf(inVal.Index(0).Interface()) |
| 399 | if firstElementVal.Kind() == reflect.Slice { |
| 400 | inVal = firstElementVal |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | out := make([]string, inVal.Len()) |
| 406 | for i := 0; i < inVal.Len(); i++ { |
| 407 | out[i] = UserStrValue(inVal.Index(i)) |
| 408 | } |
| 409 | return out |
| 410 | } |
| 411 | |
| 412 | func Index(index int) string { |
| 413 | return fmt.Sprintf("index %d", index) |
no test coverage detected