Slices and Maps
Bind repeated and object-like values
Use slices when a tag value contains an ordered list.
roles:"['admin','editor','viewer']"type RolesTag struct {
Value []string `option:"value"`
}
func (t RolesTag) Tag() string {
return "roles"
}After parsing, Value contains the entries in the same order.
Use maps when the tag contains a small object-like value.
settings:"{'env':'prod','tier':'backend'}"type SettingsTag struct {
Value map[string]string `option:"value"`
}
func (t SettingsTag) Tag() string {
return "settings"
}Named list and map options
Lists and maps can also be named options instead of the primary value.
service:"'api',ports=[80,443],labels={'env':'prod','tier':'backend'}"type ServiceTag struct {
Name string `option:"value"`
Ports []int `option:"ports"`
Labels map[string]string `option:"labels"`
}Use this when a single tag needs a primary name plus structured metadata.
Next, use nested structs when a map-like value contains a grouped schema of its own.
