Documentation
¶
Index ¶
- Constants
- func DirExists(dirPath string) bool
- func FileExists(filePath string) bool
- func GetNewLineSeparator() string
- func GetenvOrDefault(key string, def string) string
- func IsDirEmpty(directoryPath string, treatMissingAsEmpty ...bool) (bool, error)
- func IsPathContained(basePath, targetPath string) bool
- func Rename(ctx context.Context, old, new string) error
- func ResolveContainedPath(roots []string, filePath string) (string, error)
- func RunningFromPipeline() bool
- type ExpandableMap
- type ExpandableString
- func (e ExpandableString) Empty() bool
- func (e ExpandableString) Envsubst(mapping func(string) string) (string, error)
- func (e ExpandableString) MarshalYAML() (any, error)
- func (e ExpandableString) MustEnvsubst(mapping func(string) string) string
- func (e *ExpandableString) UnmarshalYAML(unmarshal func(any) error) error
- type LazyRetryInit
- type RetryStrategy
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func DirExists ¶
DirExists checks if the given directory path exists. It returns true if the directory exists, false otherwise.
func FileExists ¶
FileExists checks if the given file path exists and is a regular file. It returns true if the file exists and is regular, false otherwise.
func GetNewLineSeparator ¶
func GetNewLineSeparator() string
func GetenvOrDefault ¶
GetenvOrDefault behaves like `os.Getenv`, except it returns a specified default value if the key is not present in the environment.
func IsDirEmpty ¶
IsDirEmpty checks if the given directory is empty. If the directory does not exist, it can either treat it as an error or as an empty directory based on the input flag. By default, it treats a missing directory as an error.
func IsPathContained ¶
IsPathContained checks whether targetPath is contained within basePath after cleaning both paths. This is used to prevent path traversal attacks where a resolved path might escape its intended directory. Backslashes in targetPath are normalized to the OS separator before checking, so paths like "..\..\malicious" are caught on all platforms.
func ResolveContainedPath ¶
ResolveContainedPath attempts to resolve filePath within one of the given root directories. It returns the first absolute path that exists and is contained within its root. If the path resolves outside all roots, it returns a path-traversal error. If the path is contained but does not exist in any root, it returns a not-found error.
func RunningFromPipeline ¶
func RunningFromPipeline() bool
Types ¶
type ExpandableMap ¶
type ExpandableMap map[string]ExpandableString
ExpandableMap is a map of string keys to ExpandableString values. It provides convenient methods for expanding all values in the map.
func (ExpandableMap) Expand ¶
Expand evaluates all ExpandableString values in the map, substituting variables as ExpandableString.Envsubst would. Returns a map[string]string with all values expanded, or an error if any expansion fails. The mapping parameter is a function that returns the value for a given variable name.
func (ExpandableMap) MustExpand ¶
func (em ExpandableMap) MustExpand(mapping func(string) string) map[string]string
MustExpand evaluates all ExpandableString values in the map and panics if any expansion fails. This is useful when you know the expansion should succeed or want to fail fast.
type ExpandableString ¶
type ExpandableString struct {
// contains filtered or unexported fields
}
ExpandableString is a string that has ${foo} style references inside which can be evaluated.
func NewExpandableString ¶
func NewExpandableString(template string) ExpandableString
func (ExpandableString) Empty ¶
func (e ExpandableString) Empty() bool
Empty returns true if the template is empty.
func (ExpandableString) Envsubst ¶
func (e ExpandableString) Envsubst(mapping func(string) string) (string, error)
Envsubst evaluates the template, substituting values as envsubst.Eval would.
func (ExpandableString) MarshalYAML ¶
func (e ExpandableString) MarshalYAML() (any, error)
func (ExpandableString) MustEnvsubst ¶
func (e ExpandableString) MustEnvsubst(mapping func(string) string) string
MustEnvsubst evaluates the template, substituting values as envsubst.Eval would and panics if there is an error (for example, the string is malformed).
func (*ExpandableString) UnmarshalYAML ¶
func (e *ExpandableString) UnmarshalYAML(unmarshal func(any) error) error
type LazyRetryInit ¶
type LazyRetryInit struct {
// contains filtered or unexported fields
}
LazyRetryInit provides a thread-safe initialization pattern that caches success but allows retries on failure. Unlike sync.Once, failed calls are not cached, so subsequent calls can retry the initialization. Uses atomic.Bool for a lock-free fast path after successful initialization.
func (*LazyRetryInit) Do ¶
func (l *LazyRetryInit) Do(f func() error) error
Do calls f if initialization has not yet succeeded. If f returns nil, the result is cached and subsequent calls return nil immediately (lock-free fast path). If f returns an error, the error is returned and f will be called again on the next invocation.
type RetryStrategy ¶
type RetryStrategy struct {
// The maximum number of retries before failing
MaxRetries uint64
// The time between each retry attempt
RetryBackoff time.Duration
}
func NewRetryStrategy ¶
func NewRetryStrategy(maxRetries uint64, retryBackoff time.Duration) *RetryStrategy
Creates a new retry strategy that also reduces the time for when running in test