util

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChunkSlice

func ChunkSlice[T any](slice []T, chunkSize int) [][]T

func CompareAsFloat64

func CompareAsFloat64(a, b any) bool

Helper to handle numeric comparisons as float64

func ExpandHomeDir

func ExpandHomeDir(pathStr string) (string, error)

func ExpandHomeDirSafe

func ExpandHomeDirSafe(pathStr string) string

func FromFloat64

func FromFloat64[T any](val float64) (T, bool)

FromFloat64 converts a float64 to the specified numeric type T Returns the converted value and a bool indicating if the conversion was successful

func GetHomeDir

func GetHomeDir() string

func GetTypedAtomValue

func GetTypedAtomValue[T any](rawVal any, atomName string) T

func IsNumericType

func IsNumericType(val any) bool

Helper to check if a value is a numeric type

func JsonValEqual

func JsonValEqual(a, b any) bool

this is a shallow equal, but with special handling for numeric types it will up convert to float64 and compare

func MapToStruct

func MapToStruct(in map[string]any, out any) error

func NumToString

func NumToString[T any](value T) (string, bool)

func OpenBrowser

func OpenBrowser(url string, delay time.Duration)

func PanicHandler

func PanicHandler(debugStr string, recoverVal any) error

PanicHandler handles panic recovery and logging. It can be called directly with recover() without checking for nil first. Example usage:

defer func() {
    util.PanicHandler("operation name", recover())
}()

func StructToMap

func StructToMap(in any) (map[string]any, error)

func ToFloat64

func ToFloat64(val any) (float64, bool)

Convert various numeric types to float64 for comparison

func ToInt

func ToInt(val any) (int, bool)

func ToInt64

func ToInt64(val any) (int64, bool)

func ValidateAtomType

func ValidateAtomType(t reflect.Type, atomName string) error

Types

type JsonFieldInfo

type JsonFieldInfo struct {
	FieldName string
	OmitEmpty bool
	AsString  bool
	Options   []string
}

func ParseJSONTag

func ParseJSONTag(field reflect.StructField) (JsonFieldInfo, bool)

Jump to

Keyboard shortcuts

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