Documentation
¶
Index ¶
- Constants
- func AdjustToEndOfDay(value any) (int64, error)
- func BuildTree[T TreeNode](nodes []T, sortField string) []T
- func Contains(a []string, x string) bool
- func ConvertToMap[T any](sm *sync.Map) map[string]T
- func ConvertToSyncMap[T any](m map[string]T) *sync.Map
- func ConvertValue(typeStr string, value string) (any, error)
- func Find(a []string, x string) int
- func FindID(a []string, x string) int
- func FormatTime(t *time.Time, layout ...string) *string
- 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 ParseLocalTime(str string) (t time.Time, err error)
- func PtrToPBTimestamp(t *time.Time) *timestamppb.Timestamp
- func RemoveDuplicates(a []string) []string
- func StringToInt(s string) (int, error)
- func StringToInt32(s string) (int32, error)
- func StringToInt64(s string) (int64, error)
- 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 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 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
- type AnyArray
- type Criterion
- type DynamicSorter
- type JSON
- type JSONArray
- type JSONData
- type MultiCriteria
- type Order
- type Sortable
- type StringArray
- type Struct
- type TreeNode
- type TypeConverter
Constants ¶
const ( ExtWindows = ".dll" ExtDarwin = ".dylib" ExtLinux = ".so" )
Platform-specific extensions
const ( PlatformWindows = "windows" PlatformDarwin = "darwin" PlatformLinux = "linux" )
Platform-specific names
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 ConvertToMap ¶
ConvertToMap 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 ConvertToSyncMap ¶
ConvertToSyncMap 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 ConvertValue ¶
ConvertValue converts a string value to the corresponding type based on the type string Supported types: string, number, boolean, object, array
func Find ¶
Find returns the smallest index i at which x == a[i], or len(a) if there is no such index.
func FormatTime ¶
FormatTime format time to string
func IsValidType ¶
IsValidType checks if the provided type string is supported Returns true for valid types: string, number, boolean, object, array
func ParseLocalTime ¶
ParseLocalTime parse to local time
func PtrToPBTimestamp ¶
func PtrToPBTimestamp(t *time.Time) *timestamppb.Timestamp
PtrToPBTimestamp convert *time.Time to *timestamppb.Timestamp
func RemoveDuplicates ¶
RemoveDuplicates removes duplicate elements from a.
func StringToInt32 ¶
StringToInt32 converts a string to an int32
func StringToInt64 ¶
StringToInt64 converts a string to an int64
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 convert time.Time to pb.Timestamp
func ToPointer ¶
func ToPointer[T any](v T) *T
ToPointer is a helper function that returns a pointer to a value of any type.
func ToString ¶
ToString converts any value to its string representation Returns empty string for nil values
func ToUnixMilli ¶
func ToValue ¶
func ToValue[T any](v *T) T
ToValue is a helper function that returns the value pointed to by a pointer.
func UnixMilliToString ¶
UnixMilliToString timestamp to string
func UnixMilliToTime ¶
UnixMilliToTime timestamp to time.Time
Types ¶
type AnyArray ¶
type AnyArray = []any
AnyArray represents a slice of any type, useful for generic lists.
type Criterion ¶
type Criterion struct {
Field string `json:"field"` // Field to sort by
Order Order `json:"order"` // Sort direction
}
Criterion represents a single sorting criterion.
type DynamicSorter ¶
type DynamicSorter struct {
Data []map[string]any // Dataset to be sorted
Getter func(item map[string]any, field string) (any, error) // Field value getter
}
DynamicSorter provides a generic implementation for sorting based on criteria.
func (*DynamicSorter) Sort ¶
func (ds *DynamicSorter) Sort(criteria MultiCriteria) error
Sort sorts the dataset based on the given MultiCriteria.
type JSONData ¶
type JSONData struct {
Data JSON `json:"data,omitempty"`
}
JSONData provides utility methods for working with JSON objects.
type MultiCriteria ¶
type MultiCriteria struct {
Criteria []Criterion `json:"criteria"` // List of sorting criteria
}
MultiCriteria supports multi-field sorting.
type Sortable ¶
type Sortable interface {
Sort(criteria MultiCriteria) error // Sort method to be implemented
}
Sortable represents a sortable dataset interface.
type StringArray ¶
type StringArray = []string
StringArray represents a slice of strings, typically used for lists of string data.
type Struct ¶
type Struct struct{}
Struct represents an empty struct, often used for signals or stateless markers.
type TreeNode ¶
type TreeNode interface {
GetID() string
GetParentID() string
SetChildren([]TreeNode)
GetChildren() []TreeNode
GetSortValue(field string) any
}
TreeNode represents a tree node.
type TypeConverter ¶
type TypeConverter struct{}
TypeConverter handles the conversion of values between different types