-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreflection_test.go
More file actions
38 lines (31 loc) · 792 Bytes
/
reflection_test.go
File metadata and controls
38 lines (31 loc) · 792 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
package html
import (
"fmt"
"reflect"
"testing"
)
// Used for mocking around with the reflect library,
// trying to figure out what is going on
type TestData struct {
Title string `css:".title"`
Description string `css:".description"`
SubSection []struct {
Field1 int `css:".field-1"`
Field2 int `css:".field-2"`
} `css:".subsection"`
}
const css = "css"
func TestReflectionExperimentation(t *testing.T) {
d := TestData{}
ty := reflect.TypeOf(d)
for i := 0; i < ty.NumField(); i++ {
field := ty.Field(i)
tag, ok := field.Tag.Lookup(css)
if ok {
fmt.Printf("Field %s had css tag with value %s and was type %v\n", field.Name, tag, field.Type)
}
if field.Type.Kind() == reflect.Slice {
fmt.Println(field.Type.Elem().Kind() == reflect.Struct)
}
}
}