O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The struct tags could be extracted with the use of the reflect package. By calling the TypeOf, we get the pointer Type for Person, subsequently, by calling the Elem we get the Type of the value which the pointer points to. 

The resulting Type gives us access to the struct type Person and its fields. By iterating over the fields and retrieving the fields, by calling the Field method, we obtain the StructField. The StructField type contains the Tag field which provides access to the struct tags. The Get method on the StructTag field then returns the specific tag.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required