| 55 | } |
| 56 | |
| 57 | func getFieldAsString(item interface{}, path string) string { |
| 58 | // Mostly inspired by https://stackoverflow.com/a/47739620 |
| 59 | e := deepGet(item, path) |
| 60 | r := reflect.ValueOf(e) |
| 61 | |
| 62 | if r.Kind() == reflect.Invalid { |
| 63 | return "" |
| 64 | } |
| 65 | |
| 66 | fieldValue := r.Interface() |
| 67 | |
| 68 | switch v := fieldValue.(type) { |
| 69 | case int: |
| 70 | return strconv.FormatInt(int64(v), 10) |
| 71 | case int32: |
| 72 | return strconv.FormatInt(int64(v), 10) |
| 73 | case int64: |
| 74 | return strconv.FormatInt(v, 10) |
| 75 | case string: |
| 76 | return v |
| 77 | case bool: |
| 78 | if v { |
| 79 | return "true" |
| 80 | } |
| 81 | return "false" |
| 82 | case time.Time: |
| 83 | return v.String() |
| 84 | default: |
| 85 | return "" |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | // method required to implement sort.Interface |
| 90 | func (s sortableByKey) Less(i, j int) bool { |