Welcome to mirror list, hosted at ThFree Co, Russian Federation.

reflect.go « reflect_util « util - github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b56f1456ff9de756dfedd763ed784ff42aef2fca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// 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
}