types

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2025 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ExtWindows = ".dll"
	ExtDarwin  = ".dylib"
	ExtLinux   = ".so"
)

Platform-specific extensions

View Source
const (
	PlatformWindows = "windows"
	PlatformDarwin  = "darwin"
	PlatformLinux   = "linux"
)

Platform-specific names

View Source
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

func AdjustToEndOfDay(value any) (int64, error)

AdjustToEndOfDay adjusts the given time to the end of the day (23:59:59).

func BuildTree

func BuildTree[T TreeNode](nodes []T, sortField string) []T

BuildTree builds a tree structure from the given nodes.

func Contains

func Contains(a []string, x string) bool

Contains tells whether a contains x.

func ConvertToMap

func ConvertToMap[T any](sm *sync.Map) map[string]T

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

func ConvertToSyncMap[T any](m map[string]T) *sync.Map

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

func ConvertValue(typeStr string, value string) (any, error)

ConvertValue converts a string value to the corresponding type based on the type string Supported types: string, number, boolean, object, array

func Find

func Find(a []string, x string) int

Find returns the smallest index i at which x == a[i], or len(a) if there is no such index.

func FindID

func FindID(a []string, x string) int

func FormatTime

func FormatTime(t *time.Time, layout ...string) *string

FormatTime format time to string

func Int64ToInt

func Int64ToInt(n int64) (int, error)

Int64ToInt converts an int64 to an int

func Int64ToString

func Int64ToString(n int64) string

Int64ToString converts an int64 to a string

func IntToInt64

func IntToInt64(n int) int64

IntToInt64 converts an int to an int64

func IntToString

func IntToString(n int) string

IntToString converts an int to a string

func IsValidType

func IsValidType(typeStr string) bool

IsValidType checks if the provided type string is supported Returns true for valid types: string, number, boolean, object, array

func ParseLocalTime

func ParseLocalTime(str string) (t time.Time, err error)

ParseLocalTime parse to local time

func PtrToPBTimestamp

func PtrToPBTimestamp(t *time.Time) *timestamppb.Timestamp

PtrToPBTimestamp convert *time.Time to *timestamppb.Timestamp

func RemoveDuplicates

func RemoveDuplicates(a []string) []string

RemoveDuplicates removes duplicate elements from a.

func StringToInt

func StringToInt(s string) (int, error)

StringToInt converts a string to an int

func StringToInt32

func StringToInt32(s string) (int32, error)

StringToInt32 converts a string to an int32

func StringToInt64

func StringToInt64(s string) (int64, error)

StringToInt64 converts a string to an int64

func ToArray

func ToArray(value any) ([]any, error)

ToArray attempts to convert a value to []interface{} Supports conversion from string (JSON) and existing arrays

func ToBool

func ToBool(value any) (bool, error)

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

func ToFloat(value any) (float64, error)

ToFloat attempts to convert a value to a float64 Supports conversion from string, integer types, and bool

func ToInt

func ToInt(value any) (int64, error)

ToInt attempts to convert a value to an integer Supports conversion from string, float64, bool, and integer types

func ToObject

func ToObject(value any) (map[string]any, error)

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

func ToString(value any) string

ToString converts any value to its string representation Returns empty string for nil values

func ToUnixMilli

func ToUnixMilli(v any) int64

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

func UnixMilliToString(t *int64, layout ...string) *string

UnixMilliToString timestamp to string

func UnixMilliToTime

func UnixMilliToTime(i *int64) *time.Time

UnixMilliToTime timestamp to time.Time

func UnixSecToTime

func UnixSecToTime(sec int64) time.Time

UnixSecToTime unix sec to 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 JSON

type JSON = map[string]any

JSON represents a generic JSON object, useful for handling dynamic key-value pairs.

type JSONArray

type JSONArray = []JSON

JSONArray represents an array of JSON objects.

type JSONData

type JSONData struct {
	Data JSON `json:"data,omitempty"`
}

JSONData provides utility methods for working with JSON objects.

func (*JSONData) FromBytes

func (j *JSONData) FromBytes(data []byte) error

FromBytes deserializes a byte slice into JSONData.

func (*JSONData) ToBytes

func (j *JSONData) ToBytes() ([]byte, error)

ToBytes serializes JSONData to a byte slice.

type MultiCriteria

type MultiCriteria struct {
	Criteria []Criterion `json:"criteria"` // List of sorting criteria
}

MultiCriteria supports multi-field sorting.

type Order

type Order string

Order represents sorting direction.

const (
	Ascending  Order = "asc"  // Ascending order
	Descending Order = "desc" // Descending order
)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL