upadted to 1.24.0; fixed stb and spiddped doubles in precene
This commit is contained in:
28
helper/thither/thither.go
Normal file
28
helper/thither/thither.go
Normal file
@@ -0,0 +1,28 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user