reflect.go 453 B

123456789101112131415161718192021
  1. package reflect_util
  2. import "reflect"
  3. func GetFields(t reflect.Type) []reflect.StructField {
  4. num := t.NumField()
  5. fields := make([]reflect.StructField, 0, num)
  6. for i := 0; i < num; i++ {
  7. fields = append(fields, t.Field(i))
  8. }
  9. return fields
  10. }
  11. func GetFieldValues(v reflect.Value) []reflect.Value {
  12. num := v.NumField()
  13. fields := make([]reflect.Value, 0, num)
  14. for i := 0; i < num; i++ {
  15. fields = append(fields, v.Field(i))
  16. }
  17. return fields
  18. }