Documentation
¶
Overview ¶
Package structplan builds and caches, per reflect.Type, the flattened list of settable fields on a struct, each with its config metadata already parsed from the two struct tags gostructor understands:
- cfg (routing & naming): `cfg:"base_name,source:override,source2:override"`. The first element is the field's base name; the rest are per-source key overrides.
- gos (behavior & metadata): `gos:"default:8080,sep:;,secret,optional"`, a comma-list of bare flags (secret, optional) and key:value meta (default, sep).
The reflection walk runs once per type and is reused across Configure calls rather than repeated each call. Both tags are parsed with plain strings.Split.
Index ¶
Constants ¶
const ( CfgTag = "cfg" GosTag = "gos" )
CfgTag and GosTag are the struct tag names gostructor reads.
Variables ¶
This section is empty.
Functions ¶
func ParseCfg ¶
ParseCfg splits a cfg tag value into its base name and per-source overrides. "port,env:SERVER_PORT,json:server.host" -> "port", {env:SERVER_PORT, json:server.host}. An empty tag yields an empty base and no overrides.
func ParseGos ¶
ParseGos splits a gos tag value into meta (key:value) and flags (bare tokens). "default:8080,secret,optional" -> {default:8080}, {secret, optional}.
Comma is the list separator, so a meta value may not contain a comma. For a multi-valued slice default, pick a non-comma separator with sep and use it in the default too, e.g. `gos:"sep:|,default:a|b|c"`.
Types ¶
type Field ¶
type Field struct {
Struct reflect.StructField
Index []int // path suitable for reflect.Value.FieldByIndex
// Base is the base name (first cfg element), used by each source's naming
// strategy to derive its key when no explicit override is given.
Base string
// Overrides maps a source name (e.g. "env") to the explicit key it should
// use for this field, from `cfg:"base,env:OVERRIDE"`.
Overrides map[string]string
// Meta holds gos key:value entries (e.g. "default" -> "8080").
Meta map[string]string
// Flags holds gos bare flags that are present (e.g. "secret", "optional").
Flags map[string]bool
}
Field is one leaf (non-struct) field discovered while flattening a struct's fields, including nested/embedded structs, with its cfg/gos tags parsed once and cached.