mardi 29 novembre 2016

Golang reflect: passing a sturct member variable to a function and return its tag name

   type Teacher struct {
     Name string `json:"name"`
     Age int `json:"age"`
   }


   func getTag(i interface{}) string

   getTag(teacher.Name) // print name
   getTag(teacher.Age) // print age

I wanna roll my function like the code segment, but I can't find a way to achieve this. Any Ideas?





Aucun commentaire:

Enregistrer un commentaire