Documentation ¶
Overview ¶
Helpers for type inflection and simplifying working with Golang generic interface types
Index ¶
- func Dump(in1 interface{}, in ...interface{}) string
- func Dumpf(format string, in ...interface{}) string
- func IsArray(in interface{}) bool
- func IsEmpty(value interface{}) bool
- func IsFloat(in interface{}) bool
- func IsFunction(in interface{}) bool
- func IsFunctionArity(in interface{}, inParams int, outParams int) bool
- func IsInteger(in interface{}) bool
- func IsKind(in interface{}, kinds ...reflect.Kind) bool
- func IsKindOfBool(in interface{}) bool
- func IsKindOfFloat(in interface{}) bool
- func IsKindOfInteger(in interface{}) bool
- func IsKindOfString(in interface{}) bool
- func IsMap(in interface{}) bool
- func IsNumeric(in interface{}) bool
- func IsScalar(in interface{}) bool
- func IsStruct(in interface{}) bool
- func IsZero(value interface{}) bool
- func Len(in interface{}) int
- func ResolveValue(in interface{}) interface{}
- func SetValue(target interface{}, value interface{}) error
- type Variant
- func (self Variant) Auto() interface{}
- func (self Variant) Bool() bool
- func (self Variant) Bytes() []byte
- func (self Variant) Duration() time.Duration
- func (self Variant) Float() float64
- func (self Variant) Int() int64
- func (self Variant) IsNil() bool
- func (self Variant) IsZero() bool
- func (self Variant) Map() map[Variant]Variant
- func (self Variant) MarshalJSON() ([]byte, error)
- func (self Variant) Slice() []Variant
- func (self Variant) String() string
- func (self Variant) Time() time.Time
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dump ¶
func Dump(in1 interface{}, in ...interface{}) string
Returns a pretty-printed string representation of the given values.
func IsArray ¶
func IsArray(in interface{}) bool
Returns whether the given value is a slice or array.
func IsEmpty ¶
func IsEmpty(value interface{}) bool
Returns whether the given value is "empty" in the semantic sense. Zero values are considered empty, as are arrays, slices, and maps containing only empty values (called recursively). Finally, strings are trimmed of whitespace and considered empty if the result is zero-length.
func IsFloat ¶
func IsFloat(in interface{}) bool
Returns whether the given value represents a floating point value.
func IsFunction ¶
func IsFunction(in interface{}) bool
Returns whether the given value is a function of any kind
func IsFunctionArity ¶
Returns whether the given value is a function. If inParams is not -1, the function must accept that number of arguments. If outParams is not -1, the function must return that number of values.
func IsInteger ¶
func IsInteger(in interface{}) bool
Returns whether the given value represents an integer value.
func IsKind ¶
Dectect whether the concrete underlying value of the given input is one or more Kinds of value.
func IsKindOfBool ¶
func IsKindOfBool(in interface{}) bool
func IsKindOfFloat ¶
func IsKindOfFloat(in interface{}) bool
func IsKindOfInteger ¶
func IsKindOfInteger(in interface{}) bool
func IsKindOfString ¶
func IsKindOfString(in interface{}) bool
func IsNumeric ¶
func IsNumeric(in interface{}) bool
Returns whether the given value represents a numeric value.
func IsScalar ¶
func IsScalar(in interface{}) bool
Return whether the given input is a discrete scalar value (ints, floats, bools, strings), otherwise known as "primitive types" in some other languages.
func IsZero ¶
func IsZero(value interface{}) bool
Returns whether the given value represents the underlying type's zero value
func Len ¶
func Len(in interface{}) int
Returns the length of the given value that could have a length (strings, slices, arrays, maps, and channels). If the value is not a type that has a length, -1 is returned.
func ResolveValue ¶
func ResolveValue(in interface{}) interface{}
Return the concrete value pointed to by a pointer type, or within an interface type. Allows functions receiving pointers to supported types to work with those types without doing reflection.
Types ¶
type Variant ¶
type Variant struct {
Value interface{}
}
Represents an interface type with helper functions for making it easy to do type conversions.
func (Variant) Auto ¶
func (self Variant) Auto() interface{}
Return the value automaticall converted to the appropriate type.
func (Variant) Bool ¶
Return true if the value can be interpreted as a boolean true value, or false otherwise.
func (Variant) Duration ¶
Return the value as a time.Duration if it can be interpreted as such, or zero otherwise.
func (Variant) Float ¶
Return the value as a float if it can be interpreted as such, or 0 otherwise.
func (Variant) Int ¶
Return the value as an integer if it can be interpreted as such, or 0 otherwise. Float values will be truncated to integers.
func (Variant) Map ¶
Return the value as a map[Variant]Variant if it can be interpreted as such, or nil otherwise.
func (Variant) MarshalJSON ¶
Satisfy the json.Marshaler interface
func (Variant) Slice ¶
Return the value as a slice of Variants. Scalar types will return a slice containing a single Variant element representing the value.