Tag Syntax
Learn how raw tag expressions map to schema fields
A tag expression is the raw value Tag reads from a Go struct tag. It can contain a primary value, boolean flags, and named options.
The parsing flow is:
- Read the raw struct tag.
- Match the tag name with
Tag(). - Map each value into a schema field with
option. - Use the schema as regular typed Go data.
prop:"'database.host',optional,default=5432"The expression above has three parts:
'database.host'is the primary valueoptionalis a boolean flagdefault=5432is a key/value option
The schema defines where each part should be assigned:
type PropTag struct {
Key string `option:"value"`
Optional bool `option:"optional"`
Default int `option:"default"`
}database.host is assigned to Key. optional sets Optional to true.
default=5432 is converted into the Default field.
Use this shape as the base for the rest of the guide flow. Next, map the main
positional value with option:"value".
