Documentation
¶
Index ¶
- Variables
- func AddStringToCache(value interface{}, result string)
- func AddTimeToCache(value interface{}, result time.Time)
- func AddTimeToCacheWithFormats(value interface{}, formats []string, result time.Time)
- func ClearAllCaches()
- func ClearDecoderCache()
- func ClearStringCache()
- func ClearTimeCache()
- func GetStringFromCache(value interface{}) (string, bool)
- func GetTimeFromCache(value interface{}) (time.Time, bool)
- func GetTimeFromCacheWithFormats(value interface{}, formats []string) (time.Time, bool)
- func PrependConversionPath(err error, segment string) error
- func SetDecoder(key DecoderCacheKey, decoder *Decoder)
- func SetStringCacheSize(size int)
- func SetTimeCacheSize(size int)
- type ConversionError
- type Decoder
- type DecoderCacheKey
- type FieldDecoder
Constants ¶
This section is empty.
Variables ¶
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 ¶
AddTimeToCache adds a time conversion using the default parsing formats.
func AddTimeToCacheWithFormats ¶ added in v1.2.0
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 GetStringFromCache ¶
GetStringFromCache gets a string conversion result from the cache.
func GetTimeFromCache ¶
GetTimeFromCache gets a time conversion using the default parsing formats.
func GetTimeFromCacheWithFormats ¶ added in v1.2.0
GetTimeFromCacheWithFormats gets a time conversion for the specified parsing formats.
func PrependConversionPath ¶ added in v1.2.0
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
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.