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 ¶ added in v0.2.2
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 ¶ added in v0.4.0
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 ¶ added in v0.2.2
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 ¶ added in v0.7.0
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 ¶ added in v0.7.0
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 ¶ added in v0.7.0
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 ¶ added in v0.1.1
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 ¶ added in v0.4.0
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 ¶ added in v0.2.0
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 ¶ added in v0.4.0
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 ¶ added in v0.2.0
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 ¶ added in v0.10.0
func IsZeroValue(value interface{}) bool
IsZeroValue returns TRUE if the value is the zero value for its datatype
func MapOfInterface ¶ added in v0.10.0
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 ¶ added in v0.11.0
MapOfInterfaceOk attempts to convert the generic value into a map[string]interface{} The boolean result value returns TRUE if successful. FALSE otherwise
func NullBool ¶ added in v0.7.0
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 ¶ added in v0.7.0
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 ¶ added in v0.7.0
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 ¶ added in v0.13.0
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 ¶ added in v0.11.0
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 ¶ added in v0.9.1
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 ¶ added in v0.9.1
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 ¶ added in v0.11.0
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 ¶ added in v0.10.0
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 ¶ added in v0.8.0
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 ¶ added in v0.1.3
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 ¶ added in v0.4.0
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 ¶ added in v0.2.0
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 ¶ added in v0.7.0
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 ¶ added in v0.7.0
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 ¶ added in v0.13.0
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 ¶ added in v0.7.0
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.
type Maplike ¶ added in v0.10.0
type Maplike interface {
AsMapOfInterface() map[string]interface{}
}