internal

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

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

AddTimeToCache adds time to cache.

func CacheConversion

func CacheConversion(source, target reflect.Type, convertible bool)

CacheConversion caches a type conversion result

func ClearAllCaches

func ClearAllCaches()

ClearAllCaches clears all caches

func ClearAllReflectCaches

func ClearAllReflectCaches()

ClearAllReflectCaches clears all reflection-related caches

func ClearConversionCache

func ClearConversionCache()

ClearConversionCache clears the type conversion cache

func ClearStringCache

func ClearStringCache()

Clear string cache

func ClearTimeCache

func ClearTimeCache()

Clear time cache

func ClearTypeInfoCache

func ClearTypeInfoCache()

ClearTypeInfoCache clears the type information cache

func GetCachedConversion

func GetCachedConversion(source, target reflect.Type) (bool, bool)

GetCachedConversion gets a cached type conversion result

func GetStringFromCache

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

GetStringFromCache gets string from cache.

func GetTimeFromCache

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

GetTimeFromCache gets time from cache.

func SetConversionCacheSize

func SetConversionCacheSize(size int)

SetConversionCacheSize sets the type conversion cache size

func SetStringCacheSize

func SetStringCacheSize(size int)

Set string cache size

func SetTimeCacheSize

func SetTimeCacheSize(size int)

Set time cache size

func SetTypeInfoCacheSize

func SetTypeInfoCacheSize(size int)

SetTypeInfoCacheSize sets the type information cache size

Types

type ConversionError

type ConversionError struct {
	Value      interface{}
	Type       string
	TargetType 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 ConversionPair

type ConversionPair struct {
	Source reflect.Type
	Target reflect.Type
}

ConversionPair represents a source-target type pair for conversion caching

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

func GetTypeInfo(t reflect.Type) *TypeInfo

GetTypeInfo gets reflection information about a type, preferably from cache

func (*TypeInfo) IsAssignableTo

func (ti *TypeInfo) IsAssignableTo(target reflect.Type) bool

IsAssignableTo checks if the type can be assigned to the target type, result is cached

func (*TypeInfo) IsConvertibleTo

func (ti *TypeInfo) IsConvertibleTo(target reflect.Type) bool

IsConvertibleTo checks if the type can be converted to the target type, result is cached

Jump to

Keyboard shortcuts

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