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 ¶
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 ¶
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 ¶
Package helpers provides generic helper functions with no external imports ¶
Package helpers provides generic utility functions.
Package helpers provides generic helper functions with no external imports
Index ¶
- Constants
- func BoolPtr(b bool) *bool
- func CreateDirectory(path string, mode os.FileMode) error
- func CreateFile(filepath string) error
- func CreateParentDirectory(destination string) error
- func CreatePathAndCopy(source string, destination string) error
- func CreateReproducibleTarballFromDir(dirPath, dirPrefix, tarballPath string) error
- 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 First30last30(s string) string
- func GetAvailablePort() (int, error)
- func GetCRCHash(text string) uint32
- func GetCryptoHash(data io.ReadCloser, hashName crypto.Hash) (string, error)
- func GetDirSize(path string) (int64, error)
- func GetSHA256Hash(data io.ReadCloser) (string, error)
- func GetSHA256OfFile(filePath string) (string, error)
- func InvalidPath(path string) bool
- func IsDir(path string) bool
- func IsHidden(name string) bool
- func IsNotZeroAndNotEqual[T any](given T, equal T) bool
- func IsOCIURL(source string) bool
- func IsTextFile(path string) (bool, error)
- func IsTrashBin(dirPath string) bool
- func IsURL(source string) bool
- func IsValidHostName() bool
- func ListDirectories(directory string) ([]string, error)
- 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 MergeSlices[T any](s1, s2 []T, equals EqualFunc[T]) []T
- func RandomString(length int) (string, error)
- func ReadFileByChunks(path string, chunkSizeBytes int) (chunks [][]byte, sha256sum string, err error)
- func RecursiveFileList(dir string, pattern *regexp.Regexp, skipHidden bool) (files []string, err error)
- func RemoveMatches[T any](ss []T, test func(T) bool) (r []T)
- func Retry(fn func() error, retries int, delay time.Duration, ...) error
- func Reverse[T any](s []T) (r []T)
- func SHAsMatch(path, expected string) error
- func StringToSlice(s string) []string
- 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 Truncate(text string, length int, invert bool) string
- func Unique[T comparable](s []T) (r []T)
- type ConcurrencyTools
- type DiscardProgressWriter
- type EqualFunc
- type ProgressWriter
- type Transport
Constants ¶
const ( // ReadUser is used for any internal file to be read only ReadUser = 0400 // ReadWriteUser is used for any internal file not normally used by the end user or containing sensitive data ReadWriteUser = 0600 // ReadAllWriteUser is used for any non sensitive file intended to be consumed by the end user ReadAllWriteUser = 0644 // ReadWriteExecuteUser is used for any directory or executable not normally used by the end user or containing sensitive data ReadWriteExecuteUser = 0700 // ReadExecuteAllWriteUser is used for any non sensitive directory or executable intended to be consumed by the end user ReadExecuteAllWriteUser = 0755 )
const ( OCIURLPrefix = "oci://" SGETURLPrefix = "sget://" SGETURLScheme = "sget" IPV4Localhost = "127.0.0.1" )
Nonstandard URL schemes or prefixes
Variables ¶
This section is empty.
Functions ¶
func CreateDirectory ¶ added in v0.32.6
CreateDirectory creates a directory for the given path and file mode.
func CreateFile ¶ added in v0.32.6
CreateFile creates an empty file at the given path.
func CreateParentDirectory ¶ added in v0.32.6
CreateParentDirectory creates the parent directory for the given file path.
func CreatePathAndCopy ¶ added in v0.32.6
CreatePathAndCopy creates the parent directory for the given file path and copies the source file to the destination.
func CreateReproducibleTarballFromDir ¶ added in v0.32.6
CreateReproducibleTarballFromDir creates a tarball from a directory with stripped headers
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 First30last30 ¶ added in v0.32.5
First30last30 returns the source string that has been trimmed to 30 characters at the beginning and end.
func GetAvailablePort ¶ added in v0.30.0
GetAvailablePort retrieves an available port on the host machine. This delegates the port selection to the golang net library by starting a server and then checking the port that the server is using.
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 GetDirSize ¶ added in v0.32.6
GetDirSize walks through all files and directories in the provided path and returns the total size in bytes.
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 GetSHA256OfFile ¶ added in v0.32.6
GetSHA256OfFile returns the SHA256 hash of the provided file.
func InvalidPath ¶ added in v0.32.6
InvalidPath checks if the given path is valid (if it is a permissions error it is there we just don't have access)
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 IsTextFile ¶ added in v0.32.6
IsTextFile returns true if the given file is a text file.
func IsTrashBin ¶ added in v0.32.6
IsTrashBin checks if the given directory path corresponds to an operating system's trash bin.
func IsValidHostName ¶ added in v0.30.0
func IsValidHostName() bool
IsValidHostName returns a boolean indicating if the hostname of the host machine is valid according to https://www.ietf.org/rfc/rfc1123.txt.
func ListDirectories ¶ added in v0.32.6
ListDirectories returns a list of directories in the given directory.
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 MergeSlices ¶ added in v0.31.0
MergeSlices merges two slices, s1 and s2, and returns a new slice containing all elements from s1 and only those elements from s2 that do not exist in s1 based on the provided equal function.
func RandomString ¶ added in v0.32.0
RandomString generates a secure random string of the specified length.
func ReadFileByChunks ¶ added in v0.32.6
func ReadFileByChunks(path string, chunkSizeBytes int) (chunks [][]byte, sha256sum string, err error)
ReadFileByChunks reads a file into multiple chunks by the given size.
func RecursiveFileList ¶ added in v0.32.6
func RecursiveFileList(dir string, pattern *regexp.Regexp, skipHidden bool) (files []string, err error)
RecursiveFileList walks a path with an optional regex pattern and returns a slice of file paths. If skipHidden is true, hidden directories will be skipped.
func RemoveMatches ¶
RemoveMatches removes the given element from the slice that matches the test.
func Retry ¶
func Retry(fn func() error, retries int, delay time.Duration, logger func(format string, args ...any)) error
Retry will retry a function until it succeeds or the timeout is reached. timeout == 2^attempt * delay.
func Reverse ¶
func Reverse[T any](s []T) (r []T)
Reverse returns a new slice with the elements in reverse order.
func SHAsMatch ¶ added in v0.32.6
SHAsMatch returns an error if the SHA256 hash of the provided file does not match the expected hash.
func StringToSlice ¶ added in v0.30.0
StringToSlice converts a comma-separated string to a slice of lowercase strings.
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 ¶
type ConcurrencyTools ¶ added in v0.32.5
type ConcurrencyTools[P any, E any] struct { ProgressChan chan P ErrorChan chan E Cancel context.CancelFunc // contains filtered or unexported fields }
ConcurrencyTools is a struct that contains channels and a context for use in concurrent routines
func NewConcurrencyTools ¶ added in v0.32.5
func NewConcurrencyTools[P any, E any](length int) *ConcurrencyTools[P, E]
NewConcurrencyTools creates a new ConcurrencyTools struct
Length is the number of iterations that will be performed concurrently
func (*ConcurrencyTools[P, E]) IsDone ¶ added in v0.32.5
func (ct *ConcurrencyTools[P, E]) IsDone() bool
IsDone returns true if the context is done.
func (*ConcurrencyTools[P, E]) WaitWithProgress ¶ added in v0.32.5
func (ct *ConcurrencyTools[P, E]) WaitWithProgress(onProgress func(P, int), onError func(E) error) error
WaitWithProgress waits for all routines to finish
onProgress is a callback function that is called when a routine sends a progress update
onError is a callback function that is called when a routine sends an error
func (*ConcurrencyTools[P, E]) WaitWithoutProgress ¶ added in v0.32.5
func (ct *ConcurrencyTools[P, E]) WaitWithoutProgress(onError func(E) error) error
WaitWithoutProgress waits for all routines to finish without a progress callback
onError is a callback function that is called when a routine sends an error
type DiscardProgressWriter ¶ added in v0.32.5
type DiscardProgressWriter struct{}
DiscardProgressWriter is a ProgressWriter in which all calls succeed without doing anything Use this or nil or if you don't care about writing progress
func (DiscardProgressWriter) UpdateTitle ¶ added in v0.32.5
func (DiscardProgressWriter) UpdateTitle(_ string)
UpdateTitle doesn't do anything but satisfy implementation
type EqualFunc ¶ added in v0.31.0
EqualFunc defines a type for a function that determines equality between two elements of type T.
type ProgressWriter ¶ added in v0.32.5
ProgressWriter wraps io.Writer, but also includes an updateTitle function to give the user additional context on what's going on. Useful in OCI for tracking layers
type Transport ¶ added in v0.32.5
type Transport struct { Base http.RoundTripper ProgressBar ProgressWriter }
Transport is an http.RoundTripper that keeps track of the in-flight request and add hooks to report upload progress.
func NewTransport ¶ added in v0.32.5
func NewTransport(base http.RoundTripper, bar ProgressWriter) *Transport
NewTransport returns a custom transport that tracks an http.RoundTripper and a message.ProgressBar.
func (*Transport) RoundTrip ¶ added in v0.32.5
RoundTrip is mirrored from retry, but instead of calling retry's private t.roundTrip(), this uses our own which has interactions w/ message.ProgressBar
https://github.com/oras-project/oras-go/blob/main/registry/remote/retry/client.go