util

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: Apache-2.0 Imports: 17 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 ReadLineWithTimeout added in v0.12.3

func ReadLineWithTimeout(ch chan LineOutput, timeout time.Duration) (string, error)

func StreamToLines added in v0.12.3

func StreamToLines(input io.Reader, lineFn func([]byte)) error

func StreamToLinesChan added in v0.12.3

func StreamToLinesChan(input io.Reader) chan LineOutput

starts a goroutine to drive the channel line output does not include the trailing newline

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 TruncateString added in v0.12.3

func TruncateString(s string, maxLen int) string

TruncateString truncates a string to maxLen runes (not bytes). If the string is longer than maxLen, it truncates to maxLen-3 and appends "...".

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)

type LineOutput added in v0.12.3

type LineOutput struct {
	Line  string
	Error error
}

type LineWriter added in v0.12.3

type LineWriter struct {
	// contains filtered or unexported fields
}

LineWriter is an io.Writer that processes data line-by-line via a callback. Lines do not include the trailing newline. Lines longer than maxLineLength are dropped.

func NewLineWriter added in v0.12.3

func NewLineWriter(lineFn func([]byte)) *LineWriter

NewLineWriter creates a new LineWriter with the given callback function.

func (*LineWriter) Flush added in v0.12.3

func (lw *LineWriter) Flush()

Flush outputs any remaining buffered data as a final line. Should be called when the input stream is complete (e.g., at EOF).

func (*LineWriter) Write added in v0.12.3

func (lw *LineWriter) Write(p []byte) (n int, err error)

Write implements io.Writer, processing the data and calling the callback for each complete line.

Jump to

Keyboard shortcuts

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