Documentation ¶
Overview ¶
Package helpers provides generic helper functions with no external imports
Package helpers provides generic helper functions with no external imports ¶
Package helpers provides generic helper functions with no external imports
Index ¶
- Constants
- func DoHostnamesMatch(url1 string, url2 string) (bool, error)
- func ExtractBasePathFromURL(urlStr string) (string, error)
- func Filter[T any](ss []T, test func(T) bool) (r []T)
- func Find[T any](ss []T, test func(T) bool) (r T)
- func GetCRCHash(text string) uint32
- func GetCryptoHash(data io.ReadCloser, hashName crypto.Hash) (string, error)
- func GetSHA256Hash(data io.ReadCloser) (string, error)
- func Insert[T any](slice []T, index int, element T) []T
- func IsNotZeroAndNotEqual[T any](given T, equal T) bool
- func IsOCIURL(source string) bool
- func IsURL(source string) bool
- func MatchRegex(regex *regexp.Regexp, str string) (func(string) string, error)
- func MergeMap[T any](m1, m2 map[string]T) (r map[string]T)
- func MergeMapRecursive(m1, m2 map[string]interface{}) (r map[string]interface{})
- func MergeNonZero[T any](original T, overrides T) T
- func RemoveMatches[T any](ss []T, test func(T) bool) (r []T)
- func Retry(fn func() error, retries int, delay time.Duration) (err error)
- func Reverse[T any](s []T) (r []T)
- func SliceContains[T comparable](s []T, e T) bool
- func TransformAndMergeMap[T any](m1, m2 map[string]T, transform func(string) string) (r map[string]T)
- func TransformMapKeys[T any](m map[string]T, transform func(string) string) (r map[string]T)
- func Unique[T comparable](s []T) (r []T)
Constants ¶
const ( OCIURLScheme = "oci" OCIURLPrefix = "oci://" )
Nonstandard URL schemes or prefixes
Variables ¶
This section is empty.
Functions ¶
func DoHostnamesMatch ¶ added in v0.29.0
DoHostnamesMatch returns a boolean indicating if the hostname of two different URLs are the same.
func ExtractBasePathFromURL ¶ added in v0.29.1
ExtractBasePathFromURL returns filename from URL string
func GetCRCHash ¶
GetCRCHash returns the computed CRC32 Sum of a given string
func GetCryptoHash ¶
GetCryptoHash returns the computed SHA256 Sum of a given file
func GetSHA256Hash ¶ added in v0.29.0
func GetSHA256Hash(data io.ReadCloser) (string, error)
GetSHA256Hash returns the computed SHA256 Sum of a given file
func IsNotZeroAndNotEqual ¶ added in v0.29.0
IsNotZeroAndNotEqual is used to test if a struct has zero values or is equal values with another struct
func MatchRegex ¶
MatchRegex wraps a get function around a substring match.
func MergeMapRecursive ¶
MergeMapRecursive recursively (nestedly) merges map m2 with m1 overwriting common values with m2's values.
func MergeNonZero ¶ added in v0.29.0
func MergeNonZero[T any](original T, overrides T) T
MergeNonZero is used to merge non-zero overrides from one struct into another of the same type
func RemoveMatches ¶
RemoveMatches removes the given element from the slice that matches the test.
func Retry ¶
Retry will retry a function until it succeeds or the timeout is reached, timeout == retries * delay.
func Reverse ¶
func Reverse[T any](s []T) (r []T)
Reverse returns a new slice with the elements in reverse order.
func SliceContains ¶
func SliceContains[T comparable](s []T, e T) bool
SliceContains returns true if the given element is in the slice.
func TransformAndMergeMap ¶ added in v0.29.0
func TransformAndMergeMap[T any](m1, m2 map[string]T, transform func(string) string) (r map[string]T)
TransformAndMergeMap transforms keys in both maps then merges map m2 with m1 overwriting common values with m2's values.
func TransformMapKeys ¶
TransformMapKeys takes a map and transforms its keys using the provided function.
func Unique ¶
func Unique[T comparable](s []T) (r []T)
Unique returns a new slice with only unique elements.
Types ¶
This section is empty.