Tags
Every struct tag the package reads, and the default tag priority lists.
structs is driven entirely by struct tags. Some tags name a field for lookup (which is which is set by the tag priority), and some configure how a field is bound or validated. This page lists every tag the package reads.
Behavior tags
These configure a field regardless of the lookup vocabulary.
| Tag | Purpose |
|---|---|
default:"..." | Value used when the field is left empty. Never overrides real input. |
rules:"..." | Space-separated validation rules, args after a colon (rules:"required oneof:a,b"). |
env:"..." | Env-style key for a field, glued with _ across nesting (DATABASE_URL). |
sep:"..." | Separator for splitting a single string into a slice field. Defaults to ,, and sep:"" disables splitting. |
Lookup tags
Any tag can name a field for lookup. Which one wins is set by the tag priority (WithTags, or the TagOrder in Settings). The encoding tags additionally have their ,option suffix stripped.
| Tag | Notes |
|---|---|
json, yaml, toml, xml | Encoding tags. Comma options (json:"name,omitempty") are stripped to the name. |
arg, short | Any custom tag can name a field for lookup, for example flag names read by a CLI parser. Set the priority with WithTags. |
| any custom tag | A field is looked up under whatever tags you put in the priority list. |
Default tag lists
var DefaultTags = []string{"json", "yaml"}The default tag priority for input lookup and validation.
var DefaultCLITags = []string{"arg", "short", "json", "yaml"}A ready-made priority list for a CLI app's command structs.
var DefaultEncodingTags = []string{"json", "yaml", "toml", "xml"}The tags whose values follow the stdlib name,option convention, so only these have their comma options stripped when parsed. Freeform tags (help, default, rules, ...) keep their value verbatim.
The default rule set, DefaultRules, is covered on the rules page.