utilfn

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2025 License: Apache-2.0 Imports: 15 Imported by: 15

Documentation

Index

Constants

View Source
const MaxLineLength = 64 * 1024
View Source
const MaxNameLen = 60
View Source
const MaxTagLen = 40
View Source
const SimpleTagRegexStr = `[a-zA-Z0-9][a-zA-Z0-9/_.:-]*`

Variables

View Source
var NameRegex = regexp.MustCompile(`^[a-zA-Z0-9_.#\[\]/-]+$`)
View Source
var TagRegex = regexp.MustCompile(`(?:^|\s)(#` + SimpleTagRegexStr + `)`)

must have whitespace or EOL on either side

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 CleanTag added in v0.7.4

func CleanTag(tag string) string

func CleanTagSlice added in v0.7.4

func CleanTagSlice(tags []string) []string

func CompareSemVerCore added in v0.4.4

func CompareSemVerCore(ver1, ver2 string) (int, error)

CompareSemVerCore compares two semver strings and returns -1, 0, or 1 based on just the *core* versions It ignores pre-release and build metadata Works with "v" prefixed or unprefixed versions

func ConvertMap added in v0.2.0

func ConvertMap(val any) map[string]any

func ConvertToWallClockPT

func ConvertToWallClockPT(t time.Time) time.Time

func CopyFile added in v0.9.0

func CopyFile(src, dst string) error

CopyFile copies a file from src to dst

func CopyStrArr

func CopyStrArr(arr []string) []string

func DrainChan

func DrainChan[T any](ch chan T)

func ExpandHomeDir

func ExpandHomeDir(pathStr string) string

func GetHomeDir

func GetHomeDir() string

func GetJsonTag

func GetJsonTag(field reflect.StructField) string

func GetKeys added in v0.9.0

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

func GetOrderedMapKeys

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

func InDockerEnv added in v0.8.0

func InDockerEnv() bool

func IndentString

func IndentString(indent string, str string) string

func IsASCIISpace added in v0.8.3

func IsASCIISpace(b byte) bool

func IsSemVerCore added in v0.4.4

func IsSemVerCore(ver string) bool

IsSemVerCore validates that the whole string *is exactly* a core semver

func LaunchUrl added in v0.7.0

func LaunchUrl(url string) error

MakeLaunchUrlCommand creates a command to open a URL in the default browser for the current operating system

func MoveSliceIdxToFront

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

func NeedsLock

func NeedsLock(rval reflect.Value) bool

func NormalizeName added in v0.9.0

func NormalizeName(name 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 SafeSubstring added in v0.4.3

func SafeSubstring(s string, start, end int) string

SafeSubstring safely extracts a substring from the original string based on position

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 StripPreReleaseInfo added in v0.4.4

func StripPreReleaseInfo(ver string) string

StripPreReleaseInfo extracts just the version core (major.minor.patch) from a semver string Preserves the "v" prefix if present in the original version

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) (func(), time.Duration)

func WriteFileIfDifferent

func WriteFileIfDifferent(fileName string, contents []byte, perm os.FileMode) (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