Documentation
¶
Overview ¶
Package typeconv provides utilities for converting string values to various Go types using reflection. This is useful for configuration loading, CLI parsing, and other scenarios where string data needs to be converted to strongly typed values.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnsupportedType = errors.New("typeconv: unsupported type") ErrInvalidValue = errors.New("typeconv: invalid value") )
var Default = New()
Default is the default converter instance.
Functions ¶
func ConvertTo ¶
ConvertTo converts a string value to the specified type T. This is a generic helper that returns the converted value.
func MustConvertTo ¶
MustConvertTo is like ConvertTo but panics on error.
Types ¶
type ByteSize ¶ added in v1.1.0
type ByteSize uint64
ByteSize represents a size in bytes that can be parsed from human-readable SI/IEC strings like "100K", "512Mi", "2G", "1.5TB".
func ParseByteSize ¶ added in v1.1.0
func (ByteSize) Int64 ¶ added in v1.2.1
Int64 returns the size as an int64. It returns math.MaxInt64 if the value overflows.
func (ByteSize) MarshalText ¶ added in v1.1.0
MarshalText implements encoding.TextMarshaler.
func (ByteSize) String ¶ added in v1.1.0
String returns a human-readable IEC representation (e.g. "1.5GiB").
func (*ByteSize) UnmarshalText ¶ added in v1.1.0
UnmarshalText implements encoding.TextUnmarshaler, which is used by JSON and YAML decoders to parse quoted strings.
type Converter ¶
type Converter struct {
// SliceSeparator is the string used to split slice values. Default is ",".
SliceSeparator string
// TimeLayout is the layout used for time.Time conversion. Default is time.RFC3339.
TimeLayout string
}
Converter handles conversion of string values to various Go types.