Documentation ¶
Index ¶
- Constants
- func CapitalizeString(s string) string
- func Deepcopy[T any](x T) (T, error)
- func FlattenMap(m map[string]any, delim string) map[string]any
- func IsArray(i any) bool
- func IsNumber(i any) bool
- func IsString(i any) bool
- func MapKeysToArray(m any) []any
- func ToBool(v interface{}) bool
- func ToBoolPtr(v interface{}) *bool
- func ToByte(v interface{}) byte
- func ToByteArray(v interface{}) []byte
- func ToFloat64(v interface{}) float64
- func ToFloat64Ptr(v interface{}) *float64
- func ToInt(v interface{}) int
- func ToInt64(v interface{}) int64
- func ToInt64Ptr(v interface{}) *int64
- func ToIntArray(v interface{}) []int
- func ToIntPtr(v interface{}) *int
- func ToJson(v interface{}) string
- func ToMapStringInterface(v interface{}) map[string]interface{}
- func ToMapStringString(v interface{}) map[string]string
- func ToPrettyDuration(v time.Duration, format StringFormat) string
- func ToPrettyJson(v interface{}) string
- func ToPtr[T any](a T) *T
- func ToString(v interface{}) string
- func ToStringArray(v interface{}) []string
- func ToStringOpts(v interface{}, options *Options) string
- func ToStringPtr(v interface{}) *string
- func ToStringPtrOpts(v interface{}, options *Options) *string
- func ToTime(v interface{}) time.Time
- func ToTimePtr(v interface{}) *time.Time
- func TriBool(b *bool) bool
- func TruncateByteArray(b []byte, length int) []byte
- func TruncateString(s string, length int) string
- type FieldDiff
- type Object
- func (o Object) Clone() Object
- func (o Object) ConvertStructs()
- func (o Object) Delete(key string)
- func (o Object) Diff(other Object) ObjectDiff
- func (o Object) Equals(other Object) bool
- func (o Object) FieldCount() int
- func (o Object) Flatten(delim string) Object
- func (o Object) Get(key string) any
- func (o Object) GetBool(key string, def bool) bool
- func (o Object) GetBoolPtr(key string, def bool) *bool
- func (o Object) GetBytes(key string, def []byte) []byte
- func (o Object) GetFloat64(key string, def float64) float64
- func (o Object) GetFloat64Ptr(key string, def float64) *float64
- func (o Object) GetInt(key string, def int) int
- func (o Object) GetIntPtr(key string, def int) *int
- func (o Object) GetInto(key string, ret any) any
- func (o Object) GetObject(key string) Object
- func (o Object) GetObjectArray(key string) []Object
- func (o Object) GetString(key string, def string) string
- func (o Object) GetStringArray(key string, def []string) []string
- func (o Object) GetTime(key string, def time.Time) time.Time
- func (o Object) GetTimePtr(key string, def time.Time) *time.Time
- func (o Object) JsonBytes(pretty bool) []byte
- func (o Object) JsonString(pretty bool) string
- func (o Object) Merge(other Object)
- func (o Object) MergeMissing(other Object)
- func (o Object) Move(from string, to string)
- func (o Object) RemoveNaN()
- func (o Object) Set(key string, value any)
- func (o Object) SetIfNotExist(key string, value any)
- func (o Object) SetNullIfNotExist(key string)
- func (o Object) Unmarshal(field string, raw any)
- type ObjectDiff
- type Options
- type StringFormat
Constants ¶
const ( BlankString = "(blank)" Null = "(null)" )
Variables ¶
This section is empty.
Functions ¶
func CapitalizeString ¶ added in v1.1.9
func Deepcopy ¶ added in v1.1.0
Deepcopy makes a deep copy of whatever gets passed in. It handles pretty much all known Go types (with the exception of channels, unsafe pointers, and functions). Note that this is a truly deep copy that will work it's way all the way to the leaves of the types--any pointer will be copied, any values in any slice or map will be deep copied, etc. Note: in order to avoid an infinite loop, we keep track of any pointers that we've run across. If we run into that pointer again, we don't make another deep copy of it; we just replace it with the copy we've already made. This also ensures that the cloned result is functionally equivalent to the original value.
func MapKeysToArray ¶ added in v1.1.2
func ToBool ¶
func ToBool(v interface{}) bool
ToBool converts any data type to a bool, if the conversion fails, it returns false.
func ToByteArray ¶
func ToByteArray(v interface{}) []byte
ToByteArray converts bool, string, or byte arrays, if the conversion fails, it returns false.
func ToFloat64 ¶
func ToFloat64(v interface{}) float64
ToFloat64 converts any data type to a float64, if the conversion fails, it returns NaN.
func ToFloat64Ptr ¶ added in v1.0.8
func ToFloat64Ptr(v interface{}) *float64
func ToInt ¶
func ToInt(v interface{}) int
ToInt converts any data type to a bool, if the conversion fails, it returns 0.
func ToInt64 ¶ added in v1.0.10
func ToInt64(v interface{}) int64
ToInt converts any data type to a int64, if the conversion fails, it returns 0.
func ToInt64Ptr ¶ added in v1.0.10
func ToInt64Ptr(v interface{}) *int64
func ToIntArray ¶ added in v1.2.9
func ToIntArray(v interface{}) []int
func ToMapStringInterface ¶ added in v1.0.14
func ToMapStringInterface(v interface{}) map[string]interface{}
func ToMapStringString ¶
ToMapStringString converts a generic map[string]interface{} to a map[string]string.
func ToPrettyDuration ¶ added in v1.1.10
func ToPrettyDuration(v time.Duration, format StringFormat) string
func ToPrettyJson ¶ added in v1.2.1
func ToPrettyJson(v interface{}) string
func ToString ¶
func ToString(v interface{}) string
ToString converts any data type to a string, it uses fmt.Sprintf() to convert unknown types.
func ToStringArray ¶
func ToStringArray(v interface{}) []string
ToStringArray can convert a single string to an array, useful if interface could be a string or array of strings.
func ToStringOpts ¶ added in v1.1.10
func ToStringPtr ¶ added in v1.0.8
func ToStringPtr(v interface{}) *string
func ToStringPtrOpts ¶ added in v1.0.16
func ToTime ¶
ToTime converts data types to time.Time structures. 'int' or 'int64' are treated as unix time, strings are treated as RFC3330Nano timestamps. If the conversion fails, an empty time.Time{} is returned.
func TruncateByteArray ¶ added in v1.0.15
func TruncateString ¶ added in v1.0.15
Types ¶
type Object ¶ added in v1.1.0
func NewObjectFromDelimitedString ¶ added in v1.1.10
func (Object) ConvertStructs ¶ added in v1.2.4
func (o Object) ConvertStructs()
func (Object) Diff ¶ added in v1.2.2
func (o Object) Diff(other Object) ObjectDiff
func (Object) FieldCount ¶ added in v1.1.0
func (Object) GetFloat64 ¶ added in v1.1.1
func (Object) GetFloat64Ptr ¶ added in v1.1.1
func (Object) GetObjectArray ¶ added in v1.1.0
func (Object) GetStringArray ¶ added in v1.1.0
func (Object) GetTimePtr ¶ added in v1.1.0
func (Object) JsonString ¶ added in v1.2.3
func (Object) MergeMissing ¶ added in v1.2.16
func (Object) SetIfNotExist ¶ added in v1.1.6
func (Object) SetNullIfNotExist ¶ added in v1.1.6
type ObjectDiff ¶ added in v1.2.2
type StringFormat ¶ added in v1.1.10
type StringFormat int
const ( FormatShort StringFormat = 1 FormatMedium StringFormat = 2 FormatLong StringFormat = 3 )