MCPcopy Index your code
hub / github.com/cortexlabs/cortex / UserStrs

Function UserStrs

pkg/lib/strings/stringify.go:379–410  ·  view source on GitHub ↗
(val interface{})

Source from the content-addressed store, hash-verified

377}
378
379func 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
412func Index(index int) string {
413 return fmt.Sprintf("index %d", index)

Callers 2

UserStrsOrFunction · 0.85
UserStrsAndFunction · 0.85

Calls 2

UserStrValueFunction · 0.85
LenMethod · 0.45

Tested by

no test coverage detected