utilfn

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2025 License: Apache-2.0 Imports: 13 Imported by: 15

Documentation

Index

Constants

View Source
const MaxLineLength = 64 * 1024

Variables

Functions

func AddElemToSliceUniq

func AddElemToSliceUniq[T comparable](arr []T, elem T) []T

func BoundValue

func BoundValue(val, minVal, maxVal int) int

func CalculateDeltas

func CalculateDeltas(values []float64) []float64

CalculateDeltas converts a slice of values to deltas between consecutive values The first value is kept as is, and subsequent values are the difference from the previous value If a value is exactly 0, it's treated as a counter reset and outputs 0 (not a negative delta)

func ConvertMap added in v0.2.0

func ConvertMap(val any) map[string]any

func ConvertToWallClockPT

func ConvertToWallClockPT(t time.Time) time.Time

func CopyStrArr

func CopyStrArr(arr []string) []string

func DrainChan

func DrainChan[T any](ch chan T)

func ExpandHomeDir

func ExpandHomeDir(pathStr string) string

func GetGoroutineID

func GetGoroutineID() int64

func GetHomeDir

func GetHomeDir() string

func GetJsonTag

func GetJsonTag(field reflect.StructField) string

func GetOrderedMapKeys

func GetOrderedMapKeys[V any](m map[string]V) []string

func IndentString

func IndentString(indent string, str string) string

func MoveSliceIdxToFront

func MoveSliceIdxToFront[T any](arr []T, idx int) []T

func NeedsLock

func NeedsLock(rval reflect.Value) bool

func ParseNameAndTags

func ParseNameAndTags(input string) (string, []string)

func ParseTags

func ParseTags(input string) []string

func ReUnmarshal

func ReUnmarshal(out any, in any) error

func RemoveElemFromSlice

func RemoveElemFromSlice[T comparable](arr []T, elem T) []T

removes an element from a slice and modifies the original slice (the backing elements) if it removes the last element from the slice, it will return nil so we free the original slice's backing memory

func SliceIdx

func SliceIdx[T comparable](arr []T, elem T) int

func StarMatchString

func StarMatchString(pattern string, s string, delimiter string) bool

matches a delimited string with a pattern string the pattern string can contain "*" to match a single part, or "**" to match the rest of the string note that "**" may only appear at the end of the string

func TeeCopy

func TeeCopy(src io.Reader, dst io.Writer, dataCallbackFn func([]byte)) error

TeeCopy copies data from src to dst and calls dataCallbackFn with each chunk of data

func TryLockWithTimeout

func TryLockWithTimeout(locker sync.Locker, timeout time.Duration) (bool, time.Duration)

func WriteFileIfDifferent

func WriteFileIfDifferent(fileName string, contents []byte) (bool, error)

Types

type LineBuf

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

func MakeLineBuf

func MakeLineBuf() *LineBuf

func (*LineBuf) GetPartialAndReset

func (lb *LineBuf) GetPartialAndReset() string

func (*LineBuf) ProcessBuf

func (lb *LineBuf) ProcessBuf(readBuf []byte) (lines []string)

processes the buffer, returns lines (partial lines are retained)

Jump to

Keyboard shortcuts

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