Tag|Docs

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:

  1. Read the raw struct tag.
  2. Match the tag name with Tag().
  3. Map each value into a schema field with option.
  4. 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 value
  • optional is a boolean flag
  • default=5432 is a key/value option

The schema defines where each part should be assigned:

schema.go
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".