convert

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: GPL-3.0 Imports: 5 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidDestinationType = "invalid destination type, expected: '%s'"
	ErrParseIntFailed         = "cannot parse '%s', expected integer"
	ErrParseInt8Failed        = "cannot parse '%s', expected integer of 8 bits"
	ErrParseInt16Failed       = "cannot parse '%s', expected integer of 16 bits"
	ErrParseInt32Failed       = "cannot parse '%s', expected integer of 32 bits"
	ErrParseInt64Failed       = "cannot parse '%s', expected integer of 64 bits"
	ErrParseUintFailed        = "cannot parse '%s', expected unsigned integer"
	ErrParseUint8Failed       = "cannot parse '%s', expected unsigned integer of 8 bits"
	ErrParseUint16Failed      = "cannot parse '%s', expected unsigned integer of 16 bits"
	ErrParseUint32Failed      = "cannot parse '%s', expected unsigned integer of 32 bits"
	ErrParseUint64Failed      = "cannot parse '%s', expected unsigned integer of 64 bits"
	ErrParseFloat32Failed     = "cannot parse '%s', expected float of 32 bits"
	ErrParseFloat64Failed     = "cannot parse '%s', expected float of 64 bits"
	ErrParseBoolFailed        = "cannot parse '%s', expected boolean"
	ErrInvalidDurationUnit    = "invalid duration unit, expected: '%s'"
)

Functions

func ErrorArrayToStringArray

func ErrorArrayToStringArray(errorArray []error) []string

ErrorArrayToStringArray maps an array of errors to an array of strings.

Parameters:

errorArray - pointer to a slice of errors to convert

Returns:

Slice of strings containing the error messages, or nil if input is nil or empty.

func PrettyDuration added in v0.1.10

func PrettyDuration(d time.Duration, minUnit string) (string, error)

PrettyDuration formats a duration as a human-readable string, omitting zero-value units.

Parameters:

d       - the duration to format
minUnit - the minimum unit to include (one of "ns", "us", "ms", "s", "m", "h", "d")

Returns:

A formatted string representing the duration, and an error if minUnit is invalid.

func ToBool added in v0.1.2

func ToBool(value string, dest any) error

ToBool sets the destination to the value of the string as a bool.

Parameters:

value - the string to convert
dest - pointer to a bool where the result will be stored

Returns:

An error if the conversion fails or the destination is not a pointer to bool.

func ToFloat32 added in v0.1.2

func ToFloat32(value string, dest any) error

ToFloat32 sets the destination to the value of the string as a float32.

Parameters:

value - the string to convert
dest - pointer to a float32 where the result will be stored

Returns:

An error if the conversion fails or the destination is not a pointer to float32.

func ToFloat64 added in v0.1.2

func ToFloat64(value string, dest any) error

ToFloat64 sets the destination to the value of the string as a float64.

Parameters:

value - the string to convert
dest - pointer to a float64 where the result will be stored

Returns:

An error if the conversion fails or the destination is not a pointer to float64.

func ToInt added in v0.1.2

func ToInt(value string, dest any) error

ToInt sets the destination to the value of the string as an int.

Parameters:

value - the string to convert
dest - pointer to an int where the result will be stored

Returns:

An error if the conversion fails or the destination is not a pointer to int.

func ToInt16 added in v0.1.2

func ToInt16(value string, dest any) error

ToInt16 sets the destination to the value of the string as an int16.

Parameters:

value - the string to convert
dest - pointer to an int16 where the result will be stored

Returns:

An error if the conversion fails or the destination is not a pointer to int16.

func ToInt32 added in v0.1.2

func ToInt32(value string, dest any) error

ToInt32 sets the destination to the value of the string as an int32.

Parameters:

value - the string to convert
dest - pointer to an int32 where the result will be stored

Returns:

An error if the conversion fails or the destination is not a pointer to int32.

func ToInt64 added in v0.1.2

func ToInt64(value string, dest any) error

ToInt64 sets the destination to the value of the string as an int64.

Parameters:

value - the string to convert
dest - pointer to an int64 where the result will be stored

Returns:

An error if the conversion fails or the destination is not a pointer to int64.

func ToInt8 added in v0.1.2

func ToInt8(value string, dest any) error

ToInt8 sets the destination to the value of the string as an int8.

Parameters:

value - the string to convert
dest - pointer to an int8 where the result will be stored

Returns:

An error if the conversion fails or the destination is not a pointer to int8.

func ToString added in v0.1.8

func ToString(value string, dest any) error

ToString sets the destination to the value of the string.

Parameters:

value - the string to assign
dest - pointer to a string where the value will be stored

Returns:

An error if the destination is not a pointer to string.

func ToUint added in v0.1.2

func ToUint(value string, dest any) error

ToUint sets the destination to the value of the string as a uint.

Parameters:

value - the string to convert
dest - pointer to a uint where the result will be stored

Returns:

An error if the conversion fails or the destination is not a pointer to uint.

func ToUint16 added in v0.1.2

func ToUint16(value string, dest any) error

ToUint16 sets the destination to the value of the string as a uint16.

Parameters:

value - the string to convert
dest - pointer to a uint16 where the result will be stored

Returns:

An error if the conversion fails or the destination is not a pointer to uint16.

func ToUint32 added in v0.1.2

func ToUint32(value string, dest any) error

ToUint32 sets the destination to the value of the string as a uint32.

Parameters:

value - the string to convert
dest - pointer to a uint32 where the result will be stored

Returns:

An error if the conversion fails or the destination is not a pointer to uint32.

func ToUint64 added in v0.1.2

func ToUint64(value string, dest any) error

ToUint64 sets the destination to the value of the string as a uint64.

Parameters:

value - the string to convert
dest - pointer to a uint64 where the result will be stored

Returns:

An error if the conversion fails or the destination is not a pointer to uint64.

func ToUint8 added in v0.1.2

func ToUint8(value string, dest any) error

ToUint8 sets the destination to the value of the string as a uint8.

Parameters:

value - the string to convert
dest - pointer to a uint8 where the result will be stored

Returns:

An error if the conversion fails or the destination is not a pointer to uint8.

Types

This section is empty.

Jump to

Keyboard shortcuts

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