29 lines
580 B
Go
29 lines
580 B
Go
package thither
|
|
|
|
import (
|
|
"reflect"
|
|
"strconv"
|
|
)
|
|
|
|
func FieldValueToIntSlice[T interface{}](object []T, key string) []int {
|
|
fields := make([]int, len(object))
|
|
|
|
for i, el := range object {
|
|
immutable := reflect.ValueOf(el)
|
|
fields[i] = immutable.FieldByName(key).Interface().(int)
|
|
}
|
|
|
|
return fields
|
|
}
|
|
|
|
func FieldValueToStrSlice[T interface{}](object []T, key string) []string {
|
|
fields := make([]string, len(object))
|
|
|
|
for i, el := range object {
|
|
immutable := reflect.ValueOf(el)
|
|
fields[i] = strconv.Itoa(immutable.FieldByName(key).Interface().(int))
|
|
}
|
|
|
|
return fields
|
|
}
|