github.com/golang-infrastructure/go-reflect-utils@v0.0.0-20221130143747-965ef2eb09c3/walk_test.go (about)

     1  package reflect_utils
     2  
     3  //func TestWalk(t *testing.T) {
     4  //
     5  //	// case 001. struct
     6  //	Walk(*test.NewFoo("bar1", "bar2"), func(v reflect.ItemValue) bool {
     7  //		t.Log(v.String())
     8  //		return true
     9  //	})
    10  //	t.Log("--------------------------------------------------------------------------------------------")
    11  //
    12  //	// case 002. array
    13  //	var array [2]int
    14  //	array[0] = 10086
    15  //	array[1] = 10010
    16  //	Walk(array, func(v reflect.ItemValue) bool {
    17  //		t.Log(v.Int())
    18  //		return true
    19  //	})
    20  //	t.Log("--------------------------------------------------------------------------------------------")
    21  //
    22  //	// case 003. slice
    23  //	slice := []int{1, 2, 3, 4, 5}
    24  //	Walk(slice, func(v reflect.ItemValue) bool {
    25  //		t.Log(v.Int())
    26  //		return true
    27  //	})
    28  //	t.Log("--------------------------------------------------------------------------------------------")
    29  //
    30  //}