internal

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedType   = errors.New("unsupported type")
	ErrConversionFailed  = errors.New("conversion failed")
	ErrOverflow          = errors.New("value overflow")
	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 a string conversion result to the bounded cache.

func AddTimeToCache

func AddTimeToCache(value interface{}, result time.Time)

AddTimeToCache adds a time conversion using the default parsing formats.

func AddTimeToCacheWithFormats added in v1.2.0

func AddTimeToCacheWithFormats(value interface{}, formats []string, result time.Time)

AddTimeToCacheWithFormats adds a time conversion result with its parsing formats.

func ClearAllCaches

func ClearAllCaches()

ClearAllCaches clears all active conversion and decoder caches.

func ClearDecoderCache added in v1.1.0

func ClearDecoderCache()

ClearDecoderCache clears the decoder cache.

func ClearStringCache

func ClearStringCache()

ClearStringCache clears the string conversion cache.

func ClearTimeCache

func ClearTimeCache()

ClearTimeCache clears the time conversion cache.

func GetStringFromCache

func GetStringFromCache(value interface{}) (string, bool)

GetStringFromCache gets a string conversion result from the cache.

func GetTimeFromCache

func GetTimeFromCache(value interface{}) (time.Time, bool)

GetTimeFromCache gets a time conversion using the default parsing formats.

func GetTimeFromCacheWithFormats added in v1.2.0

func GetTimeFromCacheWithFormats(value interface{}, formats []string) (time.Time, bool)

GetTimeFromCacheWithFormats gets a time conversion for the specified parsing formats.

func PrependConversionPath added in v1.2.0

func PrependConversionPath(err error, segment string) error

PrependConversionPath adds a field or collection segment to an error path.

func SetDecoder added in v1.1.0

func SetDecoder(key DecoderCacheKey, decoder *Decoder)

SetDecoder stores a decoder in the cache.

func SetStringCacheSize

func SetStringCacheSize(size int)

SetStringCacheSize sets the string cache size. A non-positive size disables it.

func SetTimeCacheSize

func SetTimeCacheSize(size int)

SetTimeCacheSize sets the time cache size. A non-positive size disables it.

Types

type ConversionError

type ConversionError struct {
	Value      interface{}
	Type       string
	TargetType string
	Path       string
	Err        error
}

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 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

type DecoderCacheKey struct {
	DestType reflect.Type
}

DecoderCacheKey identifies a decoder plan by destination type.

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
	// Depth is the number of embedded fields traversed to reach the field.
	Depth int
	// Ambiguous marks fields that collide at the same embedding depth.
	Ambiguous bool
}

FieldDecoder holds the decoding plan for a single struct field.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL