util

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteCountIEC added in v1.22.0

func ByteCountIEC(b int64) string

ByteCountIEC converts a size in bytes to a human-readable string in IEC (binary) format.

func CountTCPConnections added in v1.22.0

func CountTCPConnections(pid uint32) int

CountTCPConnections returns the number of connected TCP endpoints for a given process.

func CountUDPConnections added in v1.22.0

func CountUDPConnections(pid uint32) int

CountUDPConnections returns the number of UDP endpoints for a given process.

func DeleteFiles

func DeleteFiles(files []string)

DeleteFiles removes the given file list ignoring errors

func DownloadFile added in v1.9.0

func DownloadFile(ctx context.Context, url string) (filename, mediaType string, data []byte, err error)

DownloadFile downloads a file from the given url

func FileExists

func FileExists(path string) bool

FileExists checks whether the given path is a file

func FileNameWithoutExt added in v1.20.0

func FileNameWithoutExt(path string) string

FileNameWithoutExt returns the last element of path without the file extension.

func FindLogFiles

func FindLogFiles(path string) ([]string, []time.Time, error)

FindLogFiles returns the files and dates archived by date

func GetMapWithoutPrefix added in v1.16.0

func GetMapWithoutPrefix(set map[string]string, prefix string) map[string]string

func GetOrElse added in v1.7.1

func GetOrElse(s string, def string) string

GetOrElse returns the given string if it's non-empty, or returns the default string.

func IsDirectory added in v1.8.0

func IsDirectory(path string) (bool, error)

IsDirectory determines if a file represented by `path` is a directory or not

func MoveSlice added in v1.18.0

func MoveSlice[S ~[]E, E any](s S, i, j int)

MoveSlice moves the element s[i] to index j in s.

func PruneByTag

func PruneByTag(in interface{}, value string, tag string) (interface{}, error)

PruneByTag returns a copy of "in" that only contains fields with the given tag and value

func RandToken added in v1.20.0

func RandToken(n int) (string, error)

RandToken generates a random hex value.

func ReadFileLines

func ReadFileLines(path string, offset int64, n int) ([]string, int, int64, error)

ReadFileLines reads the last n lines in a file starting at a given offset

func RuneSizeInString added in v1.9.0

func RuneSizeInString(s string) []int

RuneSizeInString returns a slice of each character's size in the given string

func SplitExt

func SplitExt(path string) (string, string)

SplitExt splits the path into base name and file extension

func ZipFiles

func ZipFiles(filename string, files map[string]string) error

ZipFiles compresses the given file list to a zip file

Types

This section is empty.

Jump to

Keyboard shortcuts

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