Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultCacheBuilder = NewTagCacheBuilder("schema")
DefaultCacheBuilder builds struct metadata using "schema" tags.
Functions ¶
Types ¶
type CacheBuilderFunc ¶
type CacheBuilderFunc func(typ reflect.Type) (*StructMetadata, error)
CacheBuilderFunc builds struct metadata for caching.
func NewTagCacheBuilder ¶
func NewTagCacheBuilder(tagName string) CacheBuilderFunc
NewTagCacheBuilder creates a cache builder that parses struct tags. tagName specifies which tag to read (e.g., "schema", "json", "mapstructure").
type ConverterRegistry ¶
type ConverterRegistry struct {
// contains filtered or unexported fields
}
ConverterRegistry manages type converters. Immutable after construction, safe for concurrent reads.
func NewConverterRegistry ¶
func NewConverterRegistry(converters map[reflect.Type]Converter) *ConverterRegistry
NewConverterRegistry creates a registry with the given converters. If converters is nil, an empty registry is created.
func NewDefaultConverterRegistry ¶
func NewDefaultConverterRegistry(additional map[reflect.Type]Converter) *ConverterRegistry
NewDefaultConverterRegistry creates a registry with standard type converters. Additional converters can be provided to extend or override defaults.
type FieldMetadata ¶
type FieldMetadata struct {
StructFieldName string // Go field name
MapKey string // Key to lookup in map
Index int // Field index for reflection
Type reflect.Type // Field type
Embedded bool // Anonymous/embedded struct
Default *string // Raw default value from `default` tag, nil if no tag
}
FieldMetadata holds cached struct field information.
type StructMetadata ¶
type StructMetadata struct {
Fields []FieldMetadata
}
StructMetadata holds cached metadata for a struct type.
type StructMetadataCache ¶
type StructMetadataCache struct {
// contains filtered or unexported fields
}
StructMetadataCache provides caching for struct field metadata.
func NewStructMetadataCache ¶
func NewStructMetadataCache(builder CacheBuilderFunc) *StructMetadataCache
NewStructMetadataCache creates a new struct metadata cache. If builder is nil, DefaultCacheBuilder is used.
type Unmarshaler ¶
type Unmarshaler struct {
// contains filtered or unexported fields
}
Unmarshaler handles unmarshaling of maps to Go structs.
func NewDefaultUnmarshaler ¶
func NewDefaultUnmarshaler() *Unmarshaler
NewDefaultUnmarshaler creates a new unmarshaler with default settings. Uses DefaultCacheBuilder (field names) and no custom converters.
func NewUnmarshaler ¶
func NewUnmarshaler(fieldCache *StructMetadataCache, converters *ConverterRegistry) *Unmarshaler
NewUnmarshaler creates a new unmarshaler with explicit dependencies. For custom configurations, construct the cache and converters separately:
// With custom tag
cache := NewStructMetadataCache(NewTagCacheBuilder("schema"))
converters := NewDefaultConverterRegistry(nil)
u := NewUnmarshaler(cache, converters)
// With custom converters
cache := NewStructMetadataCache(DefaultCacheBuilder)
converters := NewDefaultConverterRegistry(customConverters)
u := NewUnmarshaler(cache, converters)