Documentation
¶
Index ¶
- Constants
- func AdjustToEndOfDay(value any) (int64, error)
- func ConvertValue(typeStr string, value string) (any, error)
- func Float64ToString(n float64) string
- func FormatTime(t *time.Time, layout ...string) *string
- func FromJSON(s string, v any) error
- func FromJSONMap(m map[string]any, v any) error
- func FromStringArray(arr []string, targetType string) (any, error)
- func FromSyncMap[T any](sm *sync.Map) map[string]T
- func Int64ToInt(n int64) (int, error)
- func Int64ToString(n int64) string
- func IntToInt64(n int) int64
- func IntToString(n int) string
- func IsValidType(typeStr string) bool
- func JSONUnmarshal(s string, v any) bool
- func Max(a, b int) int
- func Min(a, b int) int
- func MustFromJSON(s string, v any)
- func MustToJSON(v any) string
- func ParseJSON(s string, v any) bool
- func ParseLocalTime(str string) (t time.Time, err error)
- func ParseTimePtr(timeStr string) *time.Time
- func PrettyJSON(v any) (string, error)
- func PtrToPBTimestamp(t *time.Time) *timestamppb.Timestamp
- func StringToFloat64(s string) (float64, error)
- func StringToInt(s string) (int, error)
- func StringToInt32(s string) (int32, error)
- func StringToInt64(s string) (int64, error)
- func StringifyJSON(v any) string
- func ToArray(value any) ([]any, error)
- func ToBool(value any) (bool, error)
- func ToFloat(value any) (float64, error)
- func ToInt(value any) (int64, error)
- func ToJSON(v any) (string, error)
- func ToJSONMap(v any) (map[string]any, error)
- func ToObject(value any) (map[string]any, error)
- func ToPBTimestamp(t time.Time) *timestamppb.Timestamp
- func ToPointer[T any](v T) *T
- func ToString(value any) string
- func ToStringArray(arr any) []string
- func ToSyncMap[T any](m map[string]T) *sync.Map
- func ToTypedArray[T any](arr []string) ([]T, error)
- func ToUnixMilli(v any) int64
- func ToValue[T any](v *T) T
- func UnixMilliToString(t *int64, layout ...string) *string
- func UnixMilliToTime(i *int64) *time.Time
- func UnixSecToTime(sec int64) time.Time
Constants ¶
const ( // DefaultLayout24h default 24h layout DefaultLayout24h = "yyyy-MM-dd HH:mm:ss" // DefaultLayout12h default 12h layout DefaultLayout12h = "yyyy-MM-dd hh:mm:ss" )
Variables ¶
This section is empty.
Functions ¶
func AdjustToEndOfDay ¶
AdjustToEndOfDay adjusts the given time to the end of the day (23:59:59)
func ConvertValue ¶
ConvertValue converts a string value to the corresponding type based on the type string Supported types: string, number, boolean, object, array
func Float64ToString ¶
Float64ToString converts a float64 to a string
func FormatTime ¶
FormatTime formats time to string with optional layout
func FromJSONMap ¶
FromJSONMap deserializes map[string]any to specified object
func FromStringArray ¶
FromStringArray converts a string array to an array of a specific type The conversion is based on the target type
func FromSyncMap ¶
FromSyncMap takes a sync.Map and converts it into a regular map[string]T The function iterates over the sync.Map and retrieves each key-value pair, returning them as a standard Go map
func IsValidType ¶
IsValidType checks if the provided type string is supported Returns true for valid types: string, number, boolean, object, array
func JSONUnmarshal ¶
JSONUnmarshal unmarshals JSON string to specified object, returns false on error
func MustFromJSON ¶
MustFromJSON deserializes JSON string to specified object, panics on error
func MustToJSON ¶
MustToJSON serializes any object to JSON string, panics on error
func ParseLocalTime ¶
ParseLocalTime parses string to local time by trying multiple formats
func ParseTimePtr ¶
ParseTimePtr parses a time string into a *time.Time using multiple formats
func PrettyJSON ¶
PrettyJSON formats object as indented JSON string
func PtrToPBTimestamp ¶
func PtrToPBTimestamp(t *time.Time) *timestamppb.Timestamp
PtrToPBTimestamp converts *time.Time to *timestamppb.Timestamp
func StringToFloat64 ¶
StringToFloat64 converts a string to a float64
func StringToInt32 ¶
StringToInt32 converts a string to an int32
func StringToInt64 ¶
StringToInt64 converts a string to an int64
func StringifyJSON ¶
StringifyJSON converts object to JSON string, returns empty string on error
func ToArray ¶
ToArray attempts to convert a value to []interface{} Supports conversion from string (JSON) and existing arrays
func ToBool ¶
ToBool attempts to convert a value to a boolean Supports conversion from string, number types, and bool For strings, accepts "true", "1", "yes", "on" as true values and "false", "0", "no", "off", "" as false values
func ToFloat ¶
ToFloat attempts to convert a value to a float64 Supports conversion from string, integer types, and bool
func ToInt ¶
ToInt attempts to convert a value to an integer Supports conversion from string, float64, bool, and integer types
func ToObject ¶
ToObject attempts to convert a value to a map[string]interface{} Supports conversion from string (JSON) and existing maps
func ToPBTimestamp ¶
func ToPBTimestamp(t time.Time) *timestamppb.Timestamp
ToPBTimestamp converts time.Time to protobuf Timestamp
func ToString ¶
ToString converts any value to its string representation Returns empty string for nil values
func ToStringArray ¶
ToStringArray converts any type of array to a string array Each element is converted to its string representation
func ToSyncMap ¶
ToSyncMap takes a regular map[string]T and returns a pointer to a sync.Map The function copies all the key-value pairs from the regular map into the sync.Map
func ToTypedArray ¶
ToTypedArray is a generic function that converts a string array to an array of type T It handles common types (string, int, int64, float64, bool)
func ToUnixMilli ¶
ToUnixMilli converts various types to unix milliseconds timestamp
func UnixMilliToString ¶
UnixMilliToString converts unix milliseconds timestamp to string
func UnixMilliToTime ¶
UnixMilliToTime converts unix milliseconds timestamp to time.Time
func UnixSecToTime ¶
UnixSecToTime converts unix seconds to time.Time
Types ¶
This section is empty.