-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.go
More file actions
42 lines (31 loc) · 810 Bytes
/
util.go
File metadata and controls
42 lines (31 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package gofig
import (
"reflect"
"strings"
)
func pop[T any](slice *[]T) T {
length := len(*slice)
last := (*slice)[length-1]
*slice = (*slice)[:length-1]
return last
}
func getFields(t reflect.Type, parent *Field, parentValue reflect.Value) []Field {
visible := reflect.VisibleFields(t)
fields := make([]Field, len(visible))
for i, field := range visible {
currentPath := make([]string, 0)
if parent != nil {
parentPath := parent.fullPath
for _, f := range parentPath {
currentPath = append(currentPath, f)
}
}
fieldPath := field.Tag.Get("prop")
parts := strings.Split(fieldPath, ".")
for _, part := range parts {
currentPath = append(currentPath, part)
}
fields[i] = Field{field: field, parentValue: parentValue, fullPath: currentPath}
}
return fields
}