Tag|Docs

Key Value Options

Bind named options with explicit values

Use key/value options when a tag needs named values in addition to the primary value.

prop:"'database.host',default=5432"
schema.go
type PropTag struct {
	Key     string `option:"value"`
	Default int    `option:"default"`
}

Tag matches default to option:"default" and converts the raw value into the target field type.

Multiple options

Add more named options when the format needs additional explicit settings.

prop:"'database.host',default=5432,env=DB_HOST"
schema.go
type PropTag struct {
	Key     string `option:"value"`
	Default int    `option:"default"`
	Env     string `option:"env"`
}

Keep option names short and stable. They become part of the tag format that developers write in struct fields.

Next, use boolean flags for options that only need to be present or absent.

On this page