Documentation
¶
Index ¶
- Variables
- func AddStringToCache(value interface{}, result string)
- func AddTimeToCache(value interface{}, result time.Time)
- func CacheConversion(source, target reflect.Type, convertible bool)
- func ClearAllCaches()
- func ClearAllReflectCaches()
- func ClearConversionCache()
- func ClearDecoderCache()
- func ClearStringCache()
- func ClearTimeCache()
- func ClearTypeInfoCache()
- func GetCachedConversion(source, target reflect.Type) (bool, bool)
- func GetStringFromCache(value interface{}) (string, bool)
- func GetTimeFromCache(value interface{}) (time.Time, bool)
- func SetConversionCacheSize(size int)
- func SetDecoder(key DecoderCacheKey, decoder *Decoder)
- func SetStringCacheSize(size int)
- func SetTimeCacheSize(size int)
- func SetTypeInfoCacheSize(size int)
- type ConversionError
- type ConversionPair
- type Decoder
- type DecoderCacheKey
- type FieldDecoder
- type TypeInfo
Constants ¶
This section is empty.
Variables ¶
var ( ErrNilValue = errors.New("input value is nil") ErrUnsupportedType = errors.New("unsupported type") ErrConversionFailed = errors.New("conversion failed") ErrOverflow = errors.New("value overflow") ErrInvalidFormat = errors.New("invalid format") ErrInvalidTimeFormat = errors.New("invalid time format") ErrInvalidJSONFormat = errors.New("invalid JSON format") )
define errors
Functions ¶
func AddStringToCache ¶
func AddStringToCache(value interface{}, result string)
AddStringToCache adds string to cache.
func AddTimeToCache ¶
AddTimeToCache adds time to cache.
func CacheConversion ¶
CacheConversion caches a type conversion result
func ClearAllReflectCaches ¶
func ClearAllReflectCaches()
ClearAllReflectCaches clears all reflection-related caches
func ClearConversionCache ¶
func ClearConversionCache()
ClearConversionCache clears the type conversion cache
func ClearDecoderCache ¶ added in v1.1.0
func ClearDecoderCache()
ClearDecoderCache clears the decoder cache.
func ClearTypeInfoCache ¶
func ClearTypeInfoCache()
ClearTypeInfoCache clears the type information cache
func GetCachedConversion ¶
GetCachedConversion gets a cached type conversion result
func GetStringFromCache ¶
GetStringFromCache gets string from cache.
func GetTimeFromCache ¶
GetTimeFromCache gets time from cache.
func SetConversionCacheSize ¶
func SetConversionCacheSize(size int)
SetConversionCacheSize sets the type conversion cache size
func SetDecoder ¶ added in v1.1.0
func SetDecoder(key DecoderCacheKey, decoder *Decoder)
SetDecoder stores a decoder in the cache.
func SetTypeInfoCacheSize ¶
func SetTypeInfoCacheSize(size int)
SetTypeInfoCacheSize sets the type information cache size
Types ¶
type ConversionError ¶
ConversionError represents a conversion error.
func NewConversionError ¶
func NewConversionError(value interface{}, targetType string, err error) *ConversionError
NewConversionError creates a new conversion error.
func (*ConversionError) Error ¶
func (e *ConversionError) Error() string
Error implements the error interface.
func (*ConversionError) Unwrap ¶
func (e *ConversionError) Unwrap() error
Unwrap returns the underlying error.
type ConversionPair ¶
ConversionPair represents a source-target type pair for conversion caching
type Decoder ¶ added in v1.1.0
type Decoder struct {
// Fields is a map from the source map key to the field decoder.
// It's used for fast lookups.
Fields map[string]*FieldDecoder
// FieldArr is an array of all field decoders.
FieldArr []*FieldDecoder
}
Decoder holds the complete decoding plan for a struct type.
func GetDecoder ¶ added in v1.1.0
func GetDecoder(key DecoderCacheKey) (*Decoder, bool)
GetDecoder gets a decoder for a given type from the cache.
type DecoderCacheKey ¶ added in v1.1.0
DecoderCacheKey is the key for the decoder cache. It includes the destination type and the number of hooks, as different hooks can result in different decoding plans.
type FieldDecoder ¶ added in v1.1.0
type FieldDecoder struct {
// Field represents the struct field to be decoded into.
Field reflect.StructField
// Index is the field's index in the struct.
Index []int
// Name is the key name in the source map to look for.
Name string
}
FieldDecoder holds the decoding plan for a single struct field.
type TypeInfo ¶
type TypeInfo struct {
// Basic type information
Type reflect.Type
Kind reflect.Kind
IsBasic bool
IsContainer bool
// Struct field information
Fields map[string]reflect.StructField
FieldNames []string
// Method information
Methods map[string]reflect.Method
// Type conversion information
ConvertibleTo map[reflect.Type]bool
AssignableTo map[reflect.Type]bool
}
TypeInfo stores reflection information about a type
func GetTypeInfo ¶
GetTypeInfo gets reflection information about a type, preferably from cache
func (*TypeInfo) IsAssignableTo ¶
IsAssignableTo checks if the type can be assigned to the target type, result is cached