This is a created article in which the information may have evolved or changed.
Golang reflection usage, make a note.
Package Mainimport ("FMT" "reflect") type roles struct {Roleid introlename string}type User struct {Name Stringage intemail stringnickname stringtelphone introles roles}func Main () {u: = user{name: ' Name ', Age: E-mail: "Xxxx@afanty3d.com", Nickname: "Omni360", Telphone:xxxxx, roles:roles{roleid:1001, RoleName: "Administrator "}}fmt. PRINTLN (U) info (u)}func info (o interface{}) {t: = reflect. TypeOf (o) fmt. Println ("Type:", T.name ()) V: = reflect. ValueOf (o) fmt. Println ("Fileds:") for I: = 0; I < T.numfield (); i++ {f: = T.field (i) Val: = V.field (i). Interface () fmt. Printf ("%6s:%v%v\n", F.name, F.type, Val)}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.