func TestStructGetAllField(ot *testing.T) { t1 := reflect.TypeOf(&GetAllFieldT1{}) ret := kmgReflect.StructGetAllField(t1) kmgTest.Equal(len(ret), 7) kmgTest.Equal(ret[0].Name, "GetAllFieldT3") kmgTest.Equal(ret[1].Name, "GetAllFieldT4") kmgTest.Equal(ret[2].Name, "B") kmgTest.Equal(ret[2].Index, []int{2}) kmgTest.Equal(ret[3].Name, "A") kmgTest.Equal(ret[3].Index, []int{0, 0}) kmgTest.Equal(ret[4].Name, "GetAllFieldT2") kmgTest.Equal(ret[5].Name, "C") kmgTest.Equal(ret[5].Index, []int{0, 2, 2}) kmgTest.Equal(ret[6].Name, "D") kmgTest.Equal(ret[6].Index, []int{1, 1}) ret = kmgReflect.StructGetAllField(reflect.TypeOf(&GetAllFieldT5{})) kmgTest.Equal(len(ret), 2) }
func (t *structType) init() (err error) { if t.fields != nil { return } //t.fieldsMap = map[string]*structField{} for _, v := range kmgReflect.StructGetAllField(t.GetReflectType()) { s := v.Tag.Get("kmgAdmin") if s == "-" { continue } at, err := t.ctx.typeOfFromReflect(v.Type) if err != nil { return err } sf := structField{ Name: v.Name, Type: at, StructField: v, } t.fields = append(t.fields, sf) } return nil }