Documentation ¶
Index ¶
- func Bool(value any) bool
- func BoolDefault(value any, defaultValue bool) bool
- func BoolOk(value any, defaultValue bool) (bool, bool)
- func Bytes(value any) []byte
- func EpochDate(value any) int64
- func EpochDateOk(value any) (int64, bool)
- func Float(value any) float64
- func FloatDefault(value any, defaultValue float64) float64
- func FloatOk(value any, defaultValue float64) (float64, bool)
- func Int(value any) int
- func Int64(value any) int64
- func Int64Default(value any, defaultValue int64) int64
- func Int64Ok(value any, defaultValue int64) (int64, bool)
- func IntDefault(value any, defaultValue int) int
- func IntOk(value any, defaultValue int) (int, bool)
- func Interface(value any) any
- func IsZeroValue(value any) bool
- func JoinString(value any, delimiter string) string
- func MapOfAny(value any) map[string]any
- func MapOfAnyOk(value any) (map[string]any, bool)
- func NullBool(value any) null.Bool
- func NullFloat(value any) null.Float
- func NullInt(value any) null.Int
- func NullInt64(value any) null.Int64
- func ReflectType(value any) reflect.Type
- func ReflectValue(value any) reflect.Value
- func SliceLength(value any) int
- func SliceOfAny(value any) []any
- func SliceOfAnyOk(value any) ([]any, bool)
- func SliceOfBool(value any) []bool
- func SliceOfFloat(value any) []float64
- func SliceOfInt(value any) []int
- func SliceOfInt64(value any) []int64
- func SliceOfMap(value any) []map[string]any
- func SliceOfString(value any) []string
- func SplitSliceOfString(value any, sep string) []string
- func String(value any) string
- func StringDefault(value any, defaultValue string) string
- func StringOk(value any, defaultValue string) (string, bool)
- func Time(value any) time.Time
- func TimeDefault(value any, defaultValue time.Time) time.Time
- func TimeOk(value any, defaultValue time.Time) (time.Time, bool)
- type Booler
- type Floater
- type Hexer
- type Inter
- type LengthGetter
- type Maplike
- type Nuller
- type Stringer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool forces a conversion from an arbitrary value into a boolean. If the value cannot be converted, then the default value for the type is used.
func BoolDefault ¶
BoolDefault forces a conversion from an arbitrary value into a bool. if the value cannot be converted, then the default value is used.
func BoolOk ¶
BoolOk converts an arbitrary value (passed in the first parameter) into a boolean, somehow, no matter what. The first result is the final converted value, or the default value (passed in the second parameter) The second result is TRUE if the value was naturally a bool, and FALSE otherwise
Conversion Rules: Nils return default value and Ok=false Bools are passed through with Ok=true Ints and Floats all convert to FALSE if they are zero, and TRUE if they are non-zero. In these cases, Ok=false String values of "true" and "false" convert normall, and Ok=true. All other strings return the default value, with Ok=false Known interfaces (Booler, Inter, Floater, Stringer) are handled like their corresponding types All other values return the default value with Ok=false
func Bytes ¶ added in v0.5.4
Bytes forces a conversion from an arbitrary value into a slice of bytes.
func EpochDateOk ¶ added in v0.16.0
func Float ¶
Float forces a conversion from an arbitrary value into a float64. If the value cannot be converted, then the zero value for the type (false) is used.
func FloatDefault ¶
FloatDefault forces a conversion from an arbitrary value into a float64. if the value cannot be converted, then the default value is used.
func FloatOk ¶
FloatOk converts an arbitrary value (passed in the first parameter) into a float64, no matter what. The first result is the final converted value, or the default value (passed in the second parameter) The second result is TRUE if the value was naturally a floating point number, and FALSE otherwise
Conversion Rules: Nils and Bools return default value and Ok=false Ints and Floats are converted into float64, with Ok=true String values are attempted to parse as a float64. If unsuccessful, default value is returned. For all strings, Ok=false Known interfaces (Inter, Floater, Stringer) are handled like their corresponding types. All other values return the default value with Ok=false
func Int ¶
Int forces a conversion from an arbitrary value into an int. If the value cannot be converted, then the zero value for the type (0) is used.
func Int64 ¶
Int64 forces a conversion from an arbitrary value into an int. If the value cannot be converted, then the zero value for the type (0) is used.
func Int64Default ¶
Int64Default forces a conversion from an arbitrary value into a int. if the value cannot be converted, then the default value is used.
func Int64Ok ¶
Int64Ok converts an arbitrary value (passed in the first parameter) into an int, no matter what. The first result is the final converted value, or the default value (passed in the second parameter) The second result is TRUE if the value was naturally an integer, and FALSE otherwise
Conversion Rules: Nils and Bools return default value and Ok=false Int64s are returned directly with Ok=true Floats are truncated into ints. If there is no decimal value then Ok=true String values are attempted to parse as a int. If unsuccessful, default value is returned. For all strings, Ok=false Known interfaces (Int64er, Floater, Stringer) are handled like their corresponding types. All other values return the default value with Ok=false
func IntDefault ¶
IntDefault forces a conversion from an arbitrary value into a int. if the value cannot be converted, then the default value is used.
func IntOk ¶
IntOk converts an arbitrary value (passed in the first parameter) into an int, no matter what. The first result is the final converted value, or the default value (passed in the second parameter) The second result is TRUE if the value was naturally an integer, and FALSE otherwise
Conversion Rules: Nils and Bools return default value and Ok=false Ints are returned directly with Ok=true Floats are truncated into ints. If there is no decimal value then Ok=true String values are attempted to parse as a int. If unsuccessful, default value is returned. For all strings, Ok=false Known interfaces (Inter, Floater, Stringer) are handled like their corresponding types. All other values return the default value with Ok=false
func IsZeroValue ¶
IsZeroValue returns TRUE if the value is the zero value for its datatype
func JoinString ¶ added in v0.5.3
func MapOfAny ¶ added in v0.14.0
MapOfAny attempts to convert the generic value into a map[string]any The boolean result value returns TRUE if successful. FALSE otherwise
func MapOfAnyOk ¶ added in v0.14.0
MapOfAnyOk attempts to convert the generic value into a map[string]any The boolean result value returns TRUE if successful. FALSE otherwise
func NullBool ¶
NullBool converts a value into a nullable value. The value is only set if the input value is a natural match for this data type.
func NullFloat ¶
NullFloat converts a value into a nullable value. The value is only set if the input value is a natural match for this data type.
func NullInt ¶
NullInt converts a value into a nullable value. The value is only set if the input value is a natural match for this data type.
func NullInt64 ¶
NullInt64 converts a value into a nullable value. The value is only set if the input value is a natural match for this data type.
func ReflectType ¶ added in v0.6.0
func ReflectValue ¶ added in v0.6.0
func SliceLength ¶ added in v0.6.0
func SliceOfAny ¶ added in v0.14.0
SliceOfAny converts the value into a slice of any. It works with any, []any, []string, []int, []float64, string, int, and float64 values. If the passed value cannot be converted, then an empty slice is returned.
func SliceOfAnyOk ¶ added in v0.17.0
func SliceOfBool ¶
SliceOfBool converts the value into a slice of any. It works with any, []any, []string, []int, []float64, string, int, and float64 values. If the passed value cannot be converted, then an empty slice is returned.
func SliceOfFloat ¶
SliceOfFloat converts the value into a slice of floats. It works with any, []any, []float64, and float64 values. If the passed value cannot be converted, then an empty slice is returned.
func SliceOfInt ¶
SliceOfInt converts the value into a slice of ints. It works with any, []any, []string, []int, and int values. If the passed value cannot be converted, then an empty slice is returned.
func SliceOfInt64 ¶ added in v0.10.0
SliceOfInt64 converts the value into a slice of int64s. It works with any, []any, []string, []int, and int values. If the passed value cannot be converted, then an empty slice is returned.
func SliceOfMap ¶
SliceOfMap converts the value into a slice of map[string]any. It works with []any, []map[string]any. If the passed value cannot be converted, then an empty slice is returned.
func SliceOfString ¶
SliceOfString converts the value into a slice of strings. It works with any, []any, []string, and string values. If the passed value cannot be converted, then an empty slice is returned.
func SplitSliceOfString ¶ added in v0.5.2
SplitSliceOfString splits is a special case of SliceOfString. If it receives a string, Stringer, or reflect.String, it will make a slice of strings by splitting the value into a slice. All other values are passed to SliceOfString to be processed normally.
func String ¶
String forces a conversion from an arbitrary value into an string. If the value cannot be converted, then the default value for the type is used.
func StringDefault ¶
StringDefault forces a conversion from an arbitrary value into a string. if the value cannot be converted, then the default value is used.
func StringOk ¶
StringOk converts an arbitrary value (passed in the first parameter) into a string, no matter what. The first result is the final converted value, or the default value (passed in the second parameter) The second result is TRUE if the value was naturally a string, and FALSE otherwise
Conversion Rules: Nils return default value and Ok=false Bools are formated as "true" or "false" with Ok=false Ints are formated as strings with Ok=false Floats are formatted with 2 decimal places, with Ok=false String are passed through directly, with Ok=true Known interfaces (Inter, Floater, Stringer) are handled like their corresponding types. All other values return the default value with Ok=false
Types ¶
type Booler ¶
type Booler interface { // Bool returns the float64 value of the underlying object Bool() bool }
Booler interface wraps the Bool() method that enables custom types to convert themselves to bool.
type Floater ¶
type Floater interface { // Float returns the float64 value of the underlying object Float() float64 }
Floater interface wraps the Float() method that enables custom types to convert themselves to float64.
type Hexer ¶
type Hexer interface {
Hex() string
}
Hexer interface wraps the Hex() method that enables a custom type to convert itself into a hexadecimal string
type Inter ¶
type Inter interface { // Int returns the int value of the underlying object Int() int }
Inter interface wraps the Int() method that enables custom types to convert themselves to ints.
type LengthGetter ¶ added in v0.13.1
type LengthGetter interface {
Length() int
}
Length interface wraps the Length() method that returns the length of an array or map