util

package
v0.35.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteEmptyDirs added in v0.26.0

func DeleteEmptyDirs(dir string) error

DeleteEmptyDirs will delete empty directories up to the root for a given directory.

func DirCleanUpPaths added in v0.26.2

func DirCleanUpPaths(target string, preserve []string) ([]string, error)

DirCleanUpPaths will, for a given target file, list all the dirs that would be empty if the target file was deleted.

func FilepathJoiner added in v0.26.0

func FilepathJoiner(base string) func(string) string

FilepathJoiner returns a function that joins provided path with base path.

func FindClosestMatchingRoot added in v0.26.0

func FindClosestMatchingRoot(path string, roots []string) string

FindClosestMatchingRoot finds the closest matching root for a given path. If no matching root is found, an empty string is returned.

func FreePort added in v0.31.0

func FreePort(preferred ...int) (port int, err error)

FreePort returns a free port to listen on, if none of the preferred ports are available then a random free port is returned.

func Map added in v0.26.0

func Map[T, U any](a []T, f func(T) U) []U

Map applies a function to each element of a slice and returns a new slice with the results.

func Must added in v0.10.0

func Must[T any](v T, err error) T

Must takes a value and an error (as commonly returned by Go functions) and panics if the error is not nil.

func Must0 added in v0.30.0

func Must0(err error)

Must0 an error (as commonly returned by Go functions) and panics if the error is not nil.

func NullToEmpty

func NullToEmpty[T any](a []T) []T

NullToEmpty returns empty slice if provided slice is nil.

func Pointer added in v0.35.0

func Pointer[T any](v T) *T

func SafeUintToInt added in v0.31.0

func SafeUintToInt(u uint) int

SafeUintToInt will convert a uint to an int, clamping the result to math.MaxInt.

func SearchMap

func SearchMap(object map[string]any, path []string) (any, error)

SearchMap searches map for value at provided path.

Types

This section is empty.

Jump to

Keyboard shortcuts

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