Documentation ¶
Index ¶
- func Bool(value interface{}) bool
- func BoolDefault(value interface{}, defaultValue bool) bool
- func BoolOk(value interface{}, defaultValue bool) (bool, bool)
- func Float(value interface{}) float64
- func FloatDefault(value interface{}, defaultValue float64) float64
- func FloatOk(value interface{}, defaultValue float64) (float64, bool)
- func Int(value interface{}) int
- func Int64(value interface{}) int64
- func Int64Default(value interface{}, defaultValue int64) int64
- func Int64Ok(value interface{}, defaultValue int64) (int64, bool)
- func IntDefault(value interface{}, defaultValue int) int
- func IntOk(value interface{}, defaultValue int) (int, bool)
- func Interface(value any) any
- func IsZeroValue(value interface{}) bool
- func MapOfInterface(value interface{}) map[string]interface{}
- func MapOfInterfaceOk(value interface{}) (map[string]interface{}, bool)
- func NullBool(value interface{}) null.Bool
- func NullFloat(value interface{}) null.Float
- func NullInt(value interface{}) null.Int
- func NullInt64(value interface{}) null.Int64
- func SliceOfBool(value interface{}) []bool
- func SliceOfFloat(value interface{}) []float64
- func SliceOfInt(value interface{}) []int
- func SliceOfInterface(value interface{}) []interface{}
- func SliceOfMap(value interface{}) []map[string]interface{}
- func SliceOfString(value interface{}) []string
- func String(value interface{}) string
- func StringDefault(value interface{}, defaultValue string) string
- func StringOk(value interface{}, defaultValue string) (string, bool)
- type Booler
- type Floater
- type Hexer
- type Inter
- type Maplike
- type Nuller
- type Stringer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
func Bool(value interface{}) 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 Float ¶
func Float(value interface{}) float64
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 ¶
func Int(value interface{}) 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 ¶
func Int64(value interface{}) 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 ¶
func IsZeroValue(value interface{}) bool
IsZeroValue returns TRUE if the value is the zero value for its datatype
func MapOfInterface ¶
func MapOfInterface(value interface{}) map[string]interface{}
MapOfInterface attempts to convert the generic value into a map[string]interface{} The boolean result value returns TRUE if successful. FALSE otherwise
func MapOfInterfaceOk ¶
MapOfInterfaceOk attempts to convert the generic value into a map[string]interface{} 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 SliceOfBool ¶
func SliceOfBool(value interface{}) []bool
SliceOfBool converts the value into a slice of interface{}. It works with interface{}, []interface{}, []string, []int, []float64, string, int, and float64 values. If the passed value cannot be converted, then an empty slice is returned.
func SliceOfFloat ¶
func SliceOfFloat(value interface{}) []float64
SliceOfFloat converts the value into a slice of floats. It works with interface{}, []interface{}, []float64, and float64 values. If the passed value cannot be converted, then an empty slice is returned.
func SliceOfInt ¶
func SliceOfInt(value interface{}) []int
SliceOfInt converts the value into a slice of ints. It works with interface{}, []interface{}, []string, []int, and int values. If the passed value cannot be converted, then an empty slice is returned.
func SliceOfInterface ¶
func SliceOfInterface(value interface{}) []interface{}
SliceOfInterface converts the value into a slice of interface{}. It works with interface{}, []interface{}, []string, []int, []float64, string, int, and float64 values. If the passed value cannot be converted, then an empty slice is returned.
func SliceOfMap ¶
func SliceOfMap(value interface{}) []map[string]interface{}
SliceOfMap converts the value into a slice of map[string]interface{}. It works with []interface{}, []map[string]interface{}. If the passed value cannot be converted, then an empty slice is returned.
func SliceOfString ¶
func SliceOfString(value interface{}) []string
SliceOfString converts the value into a slice of strings. It works with interface{}, []interface{}, []string, and string values. If the passed value cannot be converted, then an empty slice is returned.
func String ¶
func String(value interface{}) 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() function 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() function that enables custom types to convert themselves to float64.
type Hexer ¶
type Hexer interface {
Hex() string
}
Hexer interface wraps the Hex() function 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() function that enables custom types to convert themselves to ints.