This question already has an answer here:
I've seen code like this:
type Product struct {
Name string `db:"product_name"`
Id int `db:"id"`
}
type Stocks {
Name string `db:"stock_name"`
Price float `db:"price"`
Type string `db:"type"`
}
Although this code compiles, how can it be? A member of a struct must consist of a name and a following type. However, here there's also db:"product_name"
which is the 3rd member
How can this be valid? What's db:"product_name"
from the perspective of Go?
</div>
The Go Programming Language Specification
A field declaration may be followed by an optional string literal tag, which becomes an attribute for all the fields in the corresponding field declaration. An empty tag string is equivalent to an absent tag. The tags are made visible through a reflection interface and take part in type identity for structs but are otherwise ignored.