parser
API
parser
packageAPI reference for the parser
package.
S
struct
FieldInfo
FieldInfo holds configuration metadata for a struct field.
pkg/parser/parser.go:11-16
type FieldInfo struct
Fields
| Name | Type | Description |
|---|---|---|
| Name | string | |
| EnvKey | string | |
| FlagKey | string | |
| Default | string |
F
function
Parse
Parse extracts configuration tags from a struct type.
Parameters
typ
Returns
map[string]FieldInfo
pkg/parser/parser.go:21-42
func Parse(typ reflect.Type) map[string]FieldInfo
{
info := make(map[string]FieldInfo)
fields := tagParser.ParseType(typ)
for _, field := range fields {
fi := FieldInfo{Name: field.Name}
if env := field.Get("env"); env != "" {
fi.EnvKey = env
}
if flag := field.Get("flag"); flag != "" {
fi.FlagKey = flag
}
if def := field.Get("default"); def != "" {
fi.Default = def
}
info[strings.ToLower(field.Name)] = fi
}
return info
}