2022-08-28 13:27:41 +00:00
|
|
|
package helper
|
|
|
|
|
2022-09-08 02:54:37 +00:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
)
|
|
|
|
|
2022-09-26 13:25:41 +00:00
|
|
|
func ToAny[T any](v T) any {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2023-01-21 11:31:23 +00:00
|
|
|
func StructColumnToSlice[T any, M any](arr []M, field string) (r []T) {
|
2022-09-08 02:54:37 +00:00
|
|
|
for i := 0; i < len(arr); i++ {
|
|
|
|
v := reflect.ValueOf(arr[i]).FieldByName(field).Interface()
|
|
|
|
if val, ok := v.(T); ok {
|
|
|
|
r = append(r, val)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|