utils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckVersion

func CheckVersion(versionString string, versionConstraint string) (bool, error)

CheckVersion checks whether the version satisfies the provided version constraints.

func ContextTimeout

func ContextTimeout(ctx context.Context, def time.Duration) int

ContextTimeout converts context deadline into timeout (time until it runs out). If the context has no deadline, the default timeout is returned.

func DiffSlices

func DiffSlices[T comparable](sliceA []T, sliceB []T) ([]T, []T)

DiffSlice compares two slices and returns removed and added elements. Note: Does not find differences for duplicate elemnts.

func HasAnyPrefix

func HasAnyPrefix(value string, prefixes []string) bool

HasAnyPrefix checks whether a value has any of the prefixes.

func IsSocketWritable

func IsSocketWritable(socketPath string) bool

IsSocketWritable returns true if user has write permissions for socket on the given path.

func SortMapKeys

func SortMapKeys[T any](m map[string]T) []string

SortMapKeys returns map keys sorted alphabetically.

func ToPrettyJSON

func ToPrettyJSON(v any) string

ToPrettyJSON converts the given value into JSON string. If value cannot be marshaled into JSON, an empty string is returned.

func ValueInSlice

func ValueInSlice[T comparable](value T, slice []T) bool

ValueInSlice checks whether a value is present in the given slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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