utilfn

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 19 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

Functions

func AddElemToSliceUniq

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

func AtomicRenameCopy

func AtomicRenameCopy(dstPath string, srcPath string, perms os.FileMode) error

func CompareAsFloat64

func CompareAsFloat64(a, b any) bool

Helper to handle numeric comparisons as float64

func ContainsStr

func ContainsStr(strs []string, test string) bool

func ConvertToWallClockPT

func ConvertToWallClockPT(t time.Time) time.Time

func DoMapStructure

func DoMapStructure(out any, input any) error

does a mapstructure using "json" tags

func DrainChannelSafe

func DrainChannelSafe[T any](ch <-chan T, debugName string)

DrainChannelSafe will drain a channel until it is empty or until a timeout is reached.

func DumpGoRoutineStacks

func DumpGoRoutineStacks(w io.Writer)

func FindStringInSlice

func FindStringInSlice(slice []string, val string) int

func FormatLsTime

func FormatLsTime(t time.Time) string

func GetJsonTag

func GetJsonTag(field reflect.StructField) string

func GetLineColFromOffset

func GetLineColFromOffset(barr []byte, offset int) (int, int)

func GetMapKeys

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

func GetOrderedMapKeys

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

func GracefulClose

func GracefulClose(closer io.Closer, debugName, closerName string) bool

func HasBinaryData

func HasBinaryData(data []byte) bool

func IndentString

func IndentString(indent string, str string) string

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 MoveSliceIdxToFront

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

func Ptr

func Ptr[T any](x T) *T

*

  • Utility function for referencing a type with a pointer.
  • This is the same as dereferencing with &, but unlike &
  • you can directly use it on the ouput of a function
  • without needing to create an intermediate variable

func QuickHashString

func QuickHashString(s string) string

func RandomHexString

func RandomHexString(numHexDigits int) (string, error)

every byte is 4-bits of randomness

func ReUnmarshal

func ReUnmarshal(out any, in any) error

func ReadLineWithTimeout

func ReadLineWithTimeout(ch chan LineOutput, timeout time.Duration) (string, 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 SafeDeref

func SafeDeref[T any](x *T) T

*

  • Helper function that will deref a pointer if not null
  • but returns a default value if it is null.

func ShellQuote

func ShellQuote(val string, forceQuote bool, maxLen int) string

minimum maxlen=6, pass -1 for no max length

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 StrSetIntersection

func StrSetIntersection(s1 []string, s2 []string) []string

func StreamToLines

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

func StreamToLinesChan

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 TimeoutFromContext

func TimeoutFromContext(ctx context.Context, defaultTimeout time.Duration) time.Duration

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 WriteFileIfDifferent

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

func WriteTemplateToFile

func WriteTemplateToFile(fileName string, templateText string, vars map[string]string) error

Types

type LineOutput

type LineOutput struct {
	Line  string
	Error error
}

Jump to

Keyboard shortcuts

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