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 Element(original any) any
- func Float(value any) float64
- func FloatDefault(value any, defaultValue float64) float64
- func FloatOk(value any, defaultValue float64) (float64, bool)
- func HTTPHeader(value any) http.Header
- func HTTPHeaderOk(value any) (http.Header, 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 IsMap(value any) bool
- func IsSlice(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 MapOfSliceOfString(value any) map[string][]string
- func MapOfSliceOfStringOk(value any) (map[string][]string, bool)
- func MapOfString(value any) map[string]string
- func MapOfStringOk(value any) (map[string]string, 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 Pointer[T any](original T) *T
- 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 SliceOfFloat(value any) []float64
- func SliceOfFloatOk(value any) ([]float64, bool)
- func SliceOfInt(value any) []int
- func SliceOfInt64(value any) []int64
- func SliceOfInt64Ok(value any) ([]int64, bool)
- func SliceOfIntOk(value any) ([]int, bool)
- func SliceOfMap(value any) []map[string]any
- func SliceOfMapOk(value any) ([]map[string]any, bool)
- func SliceOfString(value any) []string
- func SliceOfStringOk(value any) ([]string, bool)
- 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)
- func URLValues(value any) url.Values
- func URLValuesOk(value any) (url.Values, bool)
- type Booler
- type Floater
- type Hexer
- type Int64er
- type Inter
- type LengthGetter
- type MapOfAnyGetter
- type Nuller
- type Stringer
- type Timer
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 Element ¶ added in v0.22.4
Element defreferences a pointer, if necessary, and returns the underlying value
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 HTTPHeader ¶ added in v0.22.2
HTTPHeader converts a data structure into a http.Header object, which is a specialized instance of a map[string][]string.
func HTTPHeaderOk ¶ added in v0.22.2
HTTPHeader converts a data structure into a http.Header object, which is a specialized instance of a map[string][]string. It returns TRUE if the conversion was successful, and FALSE otherwise.
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 Interface ¶
Interface returns the value of a reflect.Value. If the value is not already a reflect.Value, then it is returned as-is.
func IsSlice ¶ added in v0.19.1
IsSlice returns TRUE if the value is a slice or array (Uses Reflection)
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
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 MapOfSliceOfString ¶ added in v0.22.2
MapOfSliceOfString converts the given value to a map[string][]string. If conversion is not possible, then an empty map is returned.
func MapOfSliceOfStringOk ¶ added in v0.22.2
MapOfSliceOfStringOk converts the given value to a map[string][]string. It returns TRUE if the conversion was successful. If conversion is not possible, then it returns an empty map and FALSE.
func MapOfString ¶ added in v0.19.0
MapOfString attempts to convert the generic value into a map[string]string
func MapOfStringOk ¶ added in v0.19.0
MapOfStringOk attempts to convert the generic value into a map[string]string 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 Pointer ¶ added in v0.22.4
func Pointer[T any](original T) *T
Pointer returns a pointer to the original value
func ReflectType ¶ added in v0.6.0
ReflectType returns the reflect.Type of the given argument. If the argument is already a reflect.Type, then it is returned as-is.
func ReflectValue ¶ added in v0.6.0
ReflectValue returns the reflect.Value of the given argument. If the argument is already a reflect.Value, then it is returned as-is.
func SliceLength ¶ added in v0.6.0
SliceLength returns the length of any slice
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
SliceOfAny converts the value into a slice of any. It works with any, []any, []string, []int, []float64, string, int, and float64 values. It returns TRUE if the conversion was successful, and FALSE otherwise.
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 SliceOfFloatOk ¶ added in v0.22.2
SliceOfFloat converts the value into a slice of floats. It works with any, []any, []float64, and float64 values. It returns TRUE if the conversion was successful, and FALSE otherwise.
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 SliceOfInt64Ok ¶ added in v0.22.2
SliceOfInt64Ok converts the value into a slice of int64s. It works with float64, int, int64, string, and []any, []float64, []int, []int64, and []string values. It returns TRUE if the conversion was successful, and FALSE otherwise.
func SliceOfIntOk ¶ added in v0.22.2
SliceOfIntOk converts the value into a slice of ints. It works with float, int, int, string, and []any, []float, []int, []int, and []string values. It returns TRUE if the conversion was successful, and FALSE otherwise.
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 SliceOfMapOk ¶ added in v0.22.2
SliceOfMapOk converts the value into a slice of map[string]any. It works with []any, []map[string]any, []map[string]string, and []MapOfAnyGetter. It returns TRUE if the conversion was successful, and FALSE otherwise.
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 SliceOfStringOk ¶ added in v0.22.2
SliceOfString converts the value into a slice of strings. It works with any, []any, []string, and string values. It returns TRUE if the value was converted successfullt, and FALSE otherwise.
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 Int64er ¶ added in v0.22.2
type Int64er interface { // Int64 returns the int64 value of the underlying object Int64() int64 }
Int64er interface wraps the Int64() method that enables custom types to convert themselves to int64s.
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
type MapOfAnyGetter ¶ added in v0.22.2
type MapOfAnyGetter interface { // MapOfAny returns the underlying data structure as a plain map[string]any MapOfAny() map[string]any }
MapOfAnyGetter wraps the MapOfAny() method that returns a data structure as a MapOfAny
type Nuller ¶
type Nuller interface { // IsNull returns TRUE if the underlying value is null IsNull() bool }
Nuller wraps the IsNull interface (implemented by the null.* package) that enables custom types to declare that their value is null (zero)