Tags

A tag for a field allows attaching meta-information to the field that can be acquired using reflection.

It is generally used to provide transformation information about how a field is encoded or decoded from another format.


type User struct {
    Name string `json:"name" xml:"name"`
🇧🇷
                        

You can use it to store any meta-information you want, whether it's for another package or for your own use.

To exemplify, the encoding/json package uses tags to find the equivalent name of each field in the json object, as shown on the side.

tags.go