Grokking Advanced Go
Vote

0% completed

​

Reflection with Struct Tags

A struct tag is a string literal written after the type of a struct field. The compiler stores that string as part of the struct type and attaches no meaning to it. While a program runs, reflection is the only way to read a tag, so a tag does nothing until some piece of code looks for it.

Packages use this to let a type describe how it should be handled, without any method on the type. The tag json:"id" means something only because the JSON package reads the key json. Any package can define a key of its own in the same way.

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content