gitee.com/gricks/utils@v1.0.8/reflect.go (about) 1 package utils 2 3 import "reflect" 4 5 type StructInfo struct { 6 Name string 7 FieldNames []string 8 } 9 10 func GetStructInfo(v interface{}) *StructInfo { 11 vt := reflect.TypeOf(v) 12 if vt.Kind() == reflect.Ptr { 13 vt = vt.Elem() 14 } 15 if vt.Kind() != reflect.Struct { 16 return nil 17 } 18 r := &StructInfo{} 19 r.Name = vt.Name() 20 for i := 0; i < vt.NumField(); i++ { 21 r.FieldNames = append(r.FieldNames, vt.Field(i).Name) 22 } 23 return r 24 }