waik: work with pointer
This commit is contained in:
		@ -6,6 +6,11 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func Walk(x interface{}, fn func(string)) {
 | 
					func Walk(x interface{}, fn func(string)) {
 | 
				
			||||||
	val := reflect.ValueOf(x)
 | 
						val := reflect.ValueOf(x)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if val.Kind() == reflect.Pointer {
 | 
				
			||||||
 | 
							val = val.Elem() // XXX: the object from the pointer
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for i := 0; i < val.NumField(); i++ {
 | 
						for i := 0; i < val.NumField(); i++ {
 | 
				
			||||||
		field := val.Field(i)
 | 
							field := val.Field(i)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -5,6 +5,14 @@ import (
 | 
				
			|||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Person struct {
 | 
				
			||||||
 | 
						Name    string
 | 
				
			||||||
 | 
						Profile struct {
 | 
				
			||||||
 | 
							Age  int
 | 
				
			||||||
 | 
							City string
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestWalk(t *testing.T) {
 | 
					func TestWalk(t *testing.T) {
 | 
				
			||||||
	cases := []struct {
 | 
						cases := []struct {
 | 
				
			||||||
		Name          string
 | 
							Name          string
 | 
				
			||||||
@ -36,13 +44,15 @@ func TestWalk(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			"nested fields",
 | 
								"nested fields",
 | 
				
			||||||
			struct {
 | 
								Person{"Chris", struct {
 | 
				
			||||||
				Name    string
 | 
									Age  int
 | 
				
			||||||
				Profile struct {
 | 
									City string
 | 
				
			||||||
					Age  int
 | 
								}{29, "London"}},
 | 
				
			||||||
					City string
 | 
								[]string{"Chris", "London"},
 | 
				
			||||||
				}
 | 
							},
 | 
				
			||||||
			}{"Chris", struct {
 | 
							{
 | 
				
			||||||
 | 
								"pointer to things",
 | 
				
			||||||
 | 
								&Person{"Chris", struct {
 | 
				
			||||||
				Age  int
 | 
									Age  int
 | 
				
			||||||
				City string
 | 
									City string
 | 
				
			||||||
			}{29, "London"}},
 | 
								}{29, "London"}},
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user