Tag|Docs

Boolean Flags

Bind presence-only options to boolean fields

Use boolean flags for options that only need presence or absence. A flag maps to true when it appears in the tag and remains false when omitted.

prop:"'database.host',optional"
schema.go
type PropTag struct {
	Key      string `option:"value"`
	Optional bool   `option:"optional"`
}

When the optional flag is present, Optional becomes true.

When to use flags

Flags work well for small behavior switches:

  • optional
  • readonly
  • deprecated
  • inline

Use a key/value option when the setting needs a value, for example default=5432 or format=email.

Next, parse option values into concrete Go types instead of keeping everything as strings.

On this page