Documentation
¶
Index ¶
- Variables
- func ParseASCII(ctx context.Context, value interface{}) (string, error)
- func ParseAscii(ctx context.Context, value interface{}) (string, error)deprecated
- func ParseBool(ctx context.Context, value interface{}) (bool, error)
- func ParseBoolDefault(ctx context.Context, value interface{}, defaultValue bool) bool
- func ParseFloat64(ctx context.Context, value interface{}) (float64, error)
- func ParseFloat64Default(ctx context.Context, value interface{}, defaultValue float64) float64
- func ParseInt(ctx context.Context, value interface{}) (int, error)
- func ParseInt64(ctx context.Context, value interface{}) (int64, error)
- func ParseInt64Array(ctx context.Context, value interface{}) ([]int64, error)
- func ParseInt64ArrayDefault(ctx context.Context, value interface{}, defaultValue []int64) []int64
- func ParseInt64ArrayFromInterfaces(ctx context.Context, values []interface{}) ([]int64, error)
- func ParseInt64Default(ctx context.Context, value interface{}, defaultValue int64) int64
- func ParseIntArray(ctx context.Context, value interface{}) ([]int, error)
- func ParseIntArrayDefault(ctx context.Context, value interface{}, defaultValue []int) []int
- func ParseIntArrayFromInterfaces(ctx context.Context, values []interface{}) ([]int, error)
- func ParseIntDefault(ctx context.Context, value interface{}, defaultValue int) int
- func ParseString(ctx context.Context, value interface{}) (string, error)
- func ParseStringDefault(ctx context.Context, value interface{}, defaultValue string) string
- func ParseStrings(ctx context.Context, value interface{}) ([]string, error)
- func ParseStringsDefault(ctx context.Context, value interface{}, defaultValue []string) []string
- func ParseTime(ctx context.Context, value interface{}, format string) (time.Time, error)
- func ParseTimeDefault(ctx context.Context, value interface{}, format string, defaultValue time.Time) time.Time
- func ToInterfaceList[T any](values []T) []interface{}
- type HasString
- type HasStrings
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidType = stderrors.New("invalid type")
ErrInvalidType is returned when a value cannot be converted to the requested type.
Functions ¶
func ParseASCII ¶ added in v1.8.0
ParseASCII returns a the given string converted to ascii
func ParseAscii
deprecated
func ParseBool ¶
ParseBool converts an interface{} value to a bool. Supported types: bool, string (case-insensitive "true"/"false"), fmt.Stringer. String values are converted to lowercase and compared against "true" and "false". Returns an error if the value cannot be converted to bool.
func ParseBoolDefault ¶
ParseBoolDefault converts an interface{} value to a bool, returning defaultValue on error. This is a convenience wrapper around ParseBool that never returns an error.
func ParseFloat64 ¶
ParseFloat64 converts an interface{} value to a float64. Supported types: int, int32, int64, float32, float64, string, fmt.Stringer. String values are parsed using strconv.ParseFloat. Returns an error if the value cannot be converted to float64.
func ParseFloat64Default ¶
ParseFloat64Default converts an interface{} value to a float64, returning defaultValue on error. This is a convenience wrapper around ParseFloat64 that never returns an error.
func ParseInt ¶
ParseInt converts an interface{} value to an int. Supported types: int, int32, int64, float32, float64, string, fmt.Stringer. Float values are rounded to the nearest integer. String values are parsed using strconv.Atoi. Returns an error if the value cannot be converted to int.
func ParseInt64 ¶
ParseInt64 converts an interface{} value to an int64. Supported types: int64, int32, int, float32, float64, string. Float values are rounded to the nearest integer. String values are parsed using strconv.ParseInt. Returns an error if the value cannot be converted to int64.
func ParseInt64Array ¶
ParseInt64Array converts an interface{} value to an int64 slice. Supported types: []int64, []interface{}, []int, []int32, []float32, []float64, []string. Each element is converted using ParseInt64. Returns an error if the value cannot be converted to []int64.
func ParseInt64ArrayDefault ¶
ParseInt64ArrayDefault converts an interface{} value to an int64 slice, returning defaultValue on error. This is a convenience wrapper around ParseInt64Array that never returns an error.
func ParseInt64ArrayFromInterfaces ¶
ParseInt64ArrayFromInterfaces converts a slice of interface{} values to an int64 slice. Each element is converted using ParseInt64. Returns an error if any element cannot be converted to int64.
func ParseInt64Default ¶
ParseInt64Default converts an interface{} value to an int64, returning defaultValue on error. This is a convenience wrapper around ParseInt64 that never returns an error.
func ParseIntArray ¶
ParseIntArray converts an interface{} value to an int slice. Supported types: []int, []interface{}, []int32, []int64, []float32, []float64, []string. Each element is converted using ParseInt. Returns an error if the value cannot be converted to []int.
func ParseIntArrayDefault ¶
ParseIntArrayDefault converts an interface{} value to an int slice, returning defaultValue on error. This is a convenience wrapper around ParseIntArray that never returns an error.
func ParseIntArrayFromInterfaces ¶
ParseIntArrayFromInterfaces converts a slice of interface{} values to an int slice. Each element is converted using ParseInt. Returns an error if any element cannot be converted to int.
func ParseIntDefault ¶
ParseIntDefault converts an interface{} value to an int, returning defaultValue on error. This is a convenience wrapper around ParseInt that never returns an error.
func ParseString ¶
ParseString converts an interface{} value to a string. Supported types: string, bool, int, int32, int64, uint, uint32, uint64, float32, float64, fmt.Stringer. Custom types derived from string are automatically detected and handled. Returns an error if the value cannot be converted to string.
func ParseStringDefault ¶
ParseStringDefault converts an interface{} value to a string, returning defaultValue on error. This is a convenience wrapper around ParseString that never returns an error.
func ParseStrings ¶
ParseStrings converts an interface{} value to a string slice. Supported types: []string, []interface{}, []float64, []bool, []int, []int32, []int64, string, HasStrings interface, HasString interface, slices of string subtypes (e.g., []Direction where type Direction string), and slices of types implementing String() string method. A single string value is returned as a slice with one element. Returns nil for nil input. Returns an error if the value cannot be converted to []string.
func ParseStringsDefault ¶
ParseStringsDefault converts an interface{} value to a string slice, returning defaultValue on error. This is a convenience wrapper around ParseStrings that never returns an error.
func ParseTime ¶
ParseTime converts an interface{} value to a time.Time using the specified format. The value is first converted to a string using ParseString, then parsed using time.Parse. Format should follow Go's time format layout (e.g., "2006-01-02", "2006-01-02T15:04:05Z07:00"). Returns an error if the value cannot be converted to time.Time.
func ParseTimeDefault ¶
func ParseTimeDefault( ctx context.Context, value interface{}, format string, defaultValue time.Time, ) time.Time
ParseTimeDefault converts an interface{} value to a time.Time using the specified format, returning defaultValue on error. This is a convenience wrapper around ParseTime that never returns an error.
func ToInterfaceList ¶
func ToInterfaceList[T any](values []T) []interface{}
ToInterfaceList converts a typed slice to a slice of interface{}. This is a generic helper function used internally for type conversion.
Types ¶
type HasString ¶ added in v1.9.0
type HasString interface {
String() string
}
HasString interface is implemented by types that can provide a string representation. This is similar to fmt.Stringer but used specifically for ParseStrings conversion.
type HasStrings ¶ added in v1.9.0
type HasStrings interface {
Strings() []string
}
HasStrings interface is implemented by types that can provide a string slice representation.