utils

package
v1.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[T comparable](slice []T, element T) bool

Contains checks if a slice contains an element - O(n)

func ContainsInt

func ContainsInt(slice []int, element int) bool

func ContainsInt64

func ContainsInt64(slice []int64, element int64) bool

func ContainsLegacy

func ContainsLegacy(slice interface{}, element interface{}) bool

ContainsLegacy checks if a slice contains a specific element (fallback) This uses reflection for non-comparable types DEPRECATED: Use typed variants (ContainsString, ContainsInt, Contains[T]) when possible

func ContainsString

func ContainsString(slice []string, element string) bool

Type-specific wrappers for Contains (for backward compatibility)

func ConvertToBool

func ConvertToBool(value string) (bool, error)

ConvertToBool converts string to bool

func ConvertToFloat

func ConvertToFloat(value string) (float64, error)

ConvertToFloat converts string to float64

func ConvertToInt

func ConvertToInt(value string) (int, error)

ConvertToInt converts string to int

func ConvertToString

func ConvertToString(value interface{}) string

ConvertToString converts various types to string

func CreateDirRecursive

func CreateDirRecursive(path string) error

func CreateFile

func CreateFile(path string) error

func DeleteDirRecursive

func DeleteDirRecursive(path string) error

func DeleteFile

func DeleteFile(path string) error

func Exists

func Exists(path string) bool

func FormatFileSize

func FormatFileSize(bytes int64) string

FormatFileSize formats a file size in bytes to human readable format

func GenerateID

func GenerateID(length int) string

GenerateID generates a random ID string

func IsEmpty

func IsEmpty[T comparable](v T) bool

IsEmpty checks if a comparable value equals its zero value

func IsEmptyLegacy

func IsEmptyLegacy(value interface{}) bool

IsEmptyLegacy checks if a value is empty (fallback for non-comparable types) This is ONLY for types that cannot be handled by IsEmpty[T] DEPRECATED: Use typed variants (IsEmptyString, IsEmptySlice[T], etc.) when possible

func IsEmptyMap

func IsEmptyMap[K comparable, V any](m map[K]V) bool

IsEmptyMap checks if a map is empty - O(1)

func IsEmptySlice

func IsEmptySlice[T any](s []T) bool

IsEmptySlice checks if a slice is empty - O(1)

func IsEmptyString

func IsEmptyString(s string) bool

IsEmptyString checks if a string is empty - O(1)

func MapKeys

func MapKeys(m interface{}) []interface{}

MapKeys returns the keys of a map as a slice

func MapValues

func MapValues(m interface{}) []interface{}

MapValues returns the values of a map as a slice

func RemoveDuplicates

func RemoveDuplicates[T comparable](slice []T) []T

RemoveDuplicates removes duplicate elements from a slice

func RemoveDuplicatesInt

func RemoveDuplicatesInt(slice []int) []int

func RemoveDuplicatesLegacy

func RemoveDuplicatesLegacy(slice interface{}) interface{}

RemoveDuplicatesLegacy removes duplicate elements from a slice (fallback with reflection) DEPRECATED: Use typed variants (RemoveDuplicatesString, RemoveDuplicatesInt, RemoveDuplicates[T]) when possible

func RemoveDuplicatesString

func RemoveDuplicatesString(slice []string) []string

Type-specific wrappers for RemoveDuplicates (for backward compatibility)

func Reverse

func Reverse[T any](slice []T)

Reverse reverses a slice in place

func ReverseInt64s

func ReverseInt64s(slice []int64)

func ReverseInts

func ReverseInts(slice []int)

func ReverseLegacy

func ReverseLegacy(slice interface{})

ReverseLegacy reverses a slice in place (fallback with reflection) DEPRECATED: Use typed variants (ReverseStrings, ReverseInts, Reverse[T]) when possible

func ReverseStrings

func ReverseStrings(slice []string)

Type-specific wrappers for Reverse (for backward compatibility)

func SliceToString

func SliceToString(slice interface{}) string

SliceToString converts a slice of any type to a comma-separated string Uses reflection only as fallback - prefer typed variants when possible

func SliceToStringInts

func SliceToStringInts(slice []int) string

func SliceToStringStrings

func SliceToStringStrings(slice []string) string

Type-specific wrappers for SliceToString

func StringToSlice

func StringToSlice(str string) []string

StringToSlice converts a comma-separated string to a slice of strings

func TimeAgo

func TimeAgo(t time.Time) string

TimeAgo returns a human-readable time difference

func TruncateString

func TruncateString(str string, length int) string

TruncateString truncates a string to a specified length

Types

This section is empty.

Jump to

Keyboard shortcuts

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