Documentation
¶
Overview ¶
Package coerce converts raw CLI values to Go types using built-in and registered parsers.
Index ¶
- Variables
- func IsPlainStringMap(mapType reflect.Type, reg Registry) bool
- func Map(raws []string, sep string) (map[string]string, error)
- func Scalar(raw string, targetType reflect.Type) (any, error)
- func ScalarWith(raw string, targetType reflect.Type, reg Registry, decodeContext DecodeContext) (any, error)
- func SliceItems(raws []string, sep string, elemType reflect.Type) []string
- func SliceWith(raws []string, sliceType reflect.Type, sep string, reg Registry, ...) (any, error)
- func SplitMapItems(raws []string, sep string) []string
- func Supports(targetType reflect.Type, reg Registry) bool
- func Value[T any](raw string) (T, error)
- type DecodeContext
- type MapEntry
- type Registry
- type TypeParser
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func IsPlainStringMap ¶ added in v0.10.0
IsPlainStringMap reports whether mapType's keys and values are both the string type with no registered parser. Such a map, or a named map type with that underlying type, binds without per-entry decoding.
func ScalarWith ¶
func ScalarWith(raw string, targetType reflect.Type, reg Registry, decodeContext DecodeContext) (any, error)
ScalarWith converts a raw string value into the target type represented by targetType, first checking if a custom parser is registered for targetType in reg. decodeContext carries the owning field's declared custom tags and the engine-configured standard streams for context-aware text unmarshaling.
func SliceItems ¶ added in v0.9.0
SliceItems splits raw slice tokens into the element items SliceWith coerces: each token is split by sep, and items are whitespace-trimmed unless splitting is disabled for a string element. Callers that inspect items before coercion (the binder's stdin check) use it so both agree on the items.
func SliceWith ¶
func SliceWith(raws []string, sliceType reflect.Type, sep string, reg Registry, decodeContext DecodeContext) (any, error)
SliceWith converts a slice of raw string tokens into a slice of targetType using the supplied custom registry. decodeContext carries the owning field's declared custom tags and the engine-configured standard streams for context-aware text unmarshaling of each element.
func SplitMapItems ¶
SplitMapItems splits raw string tokens into trimmed KEY=VALUE items using sep.
func Supports ¶ added in v0.10.0
Supports reports whether ScalarWith can decode a value of targetType with the registry reg: a registered parser for the type, its pointer, or (for a pointer type) its element; a text unmarshaler on the type's pointer (or, for a pointer type, on the type itself); or a kind with built-in parsing. It follows ScalarWith's dispatch so schema build can reject a type before any value reaches it.
Types ¶
type DecodeContext ¶
type DecodeContext = spec.DecodeContext
DecodeContext carries the ambient input for coercing one raw value into its target type. It is defined in internal/spec so schema build can recognise context-aware unmarshalers (see spec.ParsesItself).
type Registry ¶
type Registry map[reflect.Type]TypeParser[any]
Registry maps reflect.Type to registered parsers, erased to TypeParser[any].
type TypeParser ¶
TypeParser parses a raw string token into a value of type U.