package mainimport ("fmt""reflect"
)type resume struct {Name string `info:"name" doc:"我的名字"`Sex string `info:"sex"`
}func findTag(str interface{}) {t := reflect.TypeOf(str).Elem()for i := 0;i < t.NumField() ; i++ {taginfo := t.Field(i).Tag.Get("info")fmt.Println("info: ",taginfo)}}func main() {var re resumefindTag(&re)}
2
package mainimport ("fmt""reflect"
)type resume struct {Name string `info:"name" doc:"我的名字"`Sex string `info:"sex"`
}func findTag(str interface{}) {t := reflect.TypeOf(str).Elem()for i := 0;i < t.NumField() ; i++ {taginfo := t.Field(i).Tag.Get("info")tagdoc := t.Field(i).Tag.Get("doc")fmt.Println("info: ",taginfo)fmt.Println("doc",tagdoc)}}func main() {var re resumefindTag(&re)}