-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct_util_test.go
51 lines (44 loc) · 905 Bytes
/
struct_util_test.go
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
43
44
45
46
47
48
49
50
51
package henge
import (
"fmt"
"reflect"
)
func ExampleGetStructFieldIndexes() {
type Embedded2 struct {
A string // [0 0 0]
}
type Embedded1 struct {
*Embedded2 // [0 0]
B string // [0 1]
}
type Out struct {
*Embedded1 // [0]
A int // [1]
}
fieldNames := getStructFieldIndexes(reflect.ValueOf(Out{}).Type())
fmt.Println(fieldNames)
// Output:
// [[0] [0 0] [0 0 0] [0 1] [1]]
}
func ExampleGetStructFields() {
type Embedded2 struct {
A string `henge:"-"`
}
type Embedded1 struct {
*Embedded2
B string
}
type Out struct {
*Embedded1 `henge:"-"`
A int
}
for _, field := range getStructFields(reflect.ValueOf(Out{}).Type()) {
fmt.Println(field)
}
// Output:
// {Embedded1 [0] [{true}]}
// {Embedded2 [0 0] [{true} {false}]}
// {A [0 0 0] [{true} {false} {true}]}
// {B [0 1] [{true} {false}]}
// {A [1] [{false}]}
}