3x-ui/util/reflect_util/reflect.go
2026-01-04 20:21:02 +03:00

24 lines
675 B
Go

// Package reflect_util provides reflection utilities for working with struct fields and values.
package reflect_util
import "reflect"
// GetFields returns all struct fields of the given reflect.Type.
func GetFields(t reflect.Type) []reflect.StructField {
num := t.NumField()
fields := make([]reflect.StructField, 0, num)
for i := range num {
fields = append(fields, t.Field(i))
}
return fields
}
// GetFieldValues returns all field values of the given reflect.Value.
func GetFieldValues(v reflect.Value) []reflect.Value {
num := v.NumField()
fields := make([]reflect.Value, 0, num)
for i := range num {
fields = append(fields, v.Field(i))
}
return fields
}