Documentation
¶
Index ¶
- Constants
- Variables
- func AppendDataNewLine(path string, data []byte, fileMode os.FileMode) error
- func AppendFile(filepath string, data []byte, mode os.FileMode) error
- func AreSemverVersionsValid(versions ...*semver.Version) error
- func CleanDirWithMkdirOption(dir, root string, doMkDir bool) (string, error)
- func CleanDirsWithMkdirOption(dirList []string, root string, doMkDir bool) error
- func CleanFilePathWithDirOption(targetPathAbsOrPartial string, dirOption string) (string, error)
- func CleanStringMap(m map[string]string) map[string]string
- func CleanStringSlice(input []string) []string
- func CleanStringSliceToLower(input []string) []string
- func CopyDir(src, dst string, opts ...CopyDirOpts) error
- func CopyFile(src, dst string) error
- func CopyFileWithPerm(srcPath, destPath string, doOverwrite bool, fileMode os.FileMode, ...) error
- func CreateTempDir() (string, error)
- func CreateTempDirWithOptions(options *TempDirOptions) (string, error)
- func DeleteDirectory(dir string, dirCommonNameForErrorMessage string, deleteDirectory bool) (string, error)
- func DirExists(dir string) bool
- func DirectoryRecreate(dir string, mode os.FileMode) error
- func EvaluateMockRootDir(mockDir string, rootDir string, deleteRoot bool) error
- func Exists(target string) bool
- func ExtractPlaceholderLeftRight(target string, left string, right string) (inner string, outer string)
- func ExtractPrefixBraces(target string) (inner string, outer string)
- func ExtractPrefixBrackets(target string) (inner string, outer string)
- func ExtractPrefixParenthesis(target string) (inner string, outer string)
- func FileExists(filename string) bool
- func FileNameParts(target string) (fullname, name, ext string)
- func GetAppPath(key AppPathKey) (string, bool)
- func GetFileNamePartExt(target string) (ext string)
- func GetFileNamePartExtNoDotPrefixToLower(target string) (ext string)
- func GetFileNamePartName(target string) (name string)
- func GetHighestSemverDirectory(dir string) (string, error)
- func GetSystemLanguage() (lang string, locale string)
- func HasAnyValidSemverVersion(versions ...*semver.Version) bool
- func HasPrefixPath(target string, prefixPaths []string) bool
- func IsDirEmpty(path string) (bool, error)
- func IsDirectory(target string) (bool, error)
- func IsFile(target string) (bool, error)
- func IsFileContentIdentical(file1 string, file2 string) (bool, error)
- func IsPathWithin(base, target string) (bool, error)
- func IsSemverValid(version ...*semver.Version) bool
- func IsSemverVersionInvalid(version *semver.Version) error
- func IsUnderRoot(root, path string) (bool, error)
- func ListFilenamesInDir(dirPath string) []string
- func ListFilenamesInDirWithExtensions(dirPath string, exts ...string) []string
- func MergeMaps(maps ...map[string]string) map[string]string
- func MoveFileWithPerm(srcPath, destPath string, doOverwrite bool, fileMode os.FileMode, ...) error
- func MustNewVersion(version string) semver.Version
- func MustNewVersionPtr(version string) *semver.Version
- func NewNullUUIDWithValue() uuid.NullUUID
- func NewUUID() uuid.UUID
- func NewUUIDAsString() string
- func NewVersionFromString(version string, doReturnNilElseUninitialized bool) *semver.Version
- func ParseNullUUID(target string) uuid.NullUUID
- func ParseUUID(target string) uuid.UUID
- func QuickBaseName(s string) string
- func ReadByFilePathWithDirOption(targetPathAbsOrPartial string, dirOption string) ([]byte, error)
- func ReadCSV(csvReader *csv.Reader, headerLineCount int, fn FNReadCSVLine) error
- func ReadCSVFile(fileCSV string, headerLineCount int, fn FNReadCSVLine) error
- func ReadFileTrimSpace(filePath string) string
- func ReadFileTrimSpaceWithError(filePath string) (string, error)
- func ResolveDirectory(target string) (string, error)
- func ResolveFile(target string) (string, error)
- func SanitizeName(name string) string
- func ScanFileByLine(filePath string, fnScanLine FNScanLine) error
- func SetAppPath(key AppPathKey, value string)
- func SetAppPathMap(apm AppPathMap) error
- func SetProcessUmask(umask int)
- func StringArrContainsString(slice []string, item string) bool
- func StripExtensionPrefix(input string) string
- func ToStringTrimLower(target string) string
- func ToStringTrimUpper(target string) string
- func UUIDToNullUUID(target uuid.UUID) uuid.NullUUID
- func UUIDToString(target uuid.UUID) string
- func UUIDToStringEmpty(target uuid.UUID) string
- type AKey
- func (rt AKey) HasMatch(rtType AKey) bool
- func (rt AKey) HasPrefix(rtType AKey) bool
- func (rt AKey) HasSuffix(rtType AKey) bool
- func (rt AKey) IsEmpty() bool
- func (rt AKey) MatchesOne(rtTypes ...AKey) bool
- func (rt AKey) String() string
- func (rt AKey) TrimSpace() AKey
- func (rt AKey) Validate() error
- type AKeys
- type AppPathKey
- type AppPathKeys
- type AppPathMap
- func (apm *AppPathMap) AutoSetupIfRootEmpty(defaults AppPathMap) error
- func (m AppPathMap) Clone() AppPathMap
- func (apm *AppPathMap) EnsureDirs(dirRoot string) error
- func (apm AppPathMap) GetPath(key AppPathKey) string
- func (apm *AppPathMap) IsRelative(key AppPathKey) bool
- func (base AppPathMap) Merge(overrides ...AppPathMap) AppPathMap
- func (base AppPathMap) MergeAbs(baseDir string, overrides ...AppPathMap) AppPathMap
- func (apm *AppPathMap) RecreateDir(key AppPathKey, mode os.FileMode) error
- func (apm *AppPathMap) RequireWithOption(dirRoot string, keys ...AppPathKey) error
- func (apm *AppPathMap) ResolveAllRelatives() error
- func (apm *AppPathMap) SetPath(key AppPathKey, pathValue string)
- func (apm *AppPathMap) SortedKeys() []AppPathKey
- func (apm *AppPathMap) Validate() error
- func (apm *AppPathMap) ValidateDir() error
- func (apm *AppPathMap) ValidateWithOption(dirRoot string) error
- type CopyDirFromTo
- type CopyDirOpts
- type CopyDirsFromTo
- type FNReadCSVLine
- type FNScanLine
- type LanguageType
- type NullUUIDs
- type Semver
- type Semvers
- type StringsArray
- type TempDirOptions
- type UUIDs
Constants ¶
const ( PATH_CHMOD_DIR os.FileMode = 0755 // Default for generic dirs PATH_CHMOD_FILE os.FileMode = 0644 // Default for generic files PATH_CHMOD_DIR_LIMIT os.FileMode = 0744 // Limited dir perms PATH_CHMOD_DIR_FULL_PERMS os.FileMode = 0777 // Full perms (rare) PATH_CHMOD_SCRIPTS os.FileMode = 0744 // Scripts executable PATH_CHMOD_DIR_SECRETS os.FileMode = 0700 // Secrets: owner only PATH_CHMOD_FILE_SECRETS os.FileMode = 0600 // Secret files PATH_CHMOD_DIR_OWNER_GROUP os.FileMode = 0750 // Owner rwx, group rx PATH_CHMOD_PATH_RO os.FileMode = 0444 // Read-only access for any path )
Define file permissions constants with comments explaining their purpose. See SetProcessUmask to set "0" globally prior to this function to have consistent behavior.
Variables ¶
var ErrEmptyPath = errors.New("file path is empty")
ErrEmptyPath indicates that the file path provided is empty.
var ErrFileNotResolved = errors.New("file could not be resolved")
ErrFileNotResolved indicates that the file could not be resolved.
var ErrNotDirectory = errors.New("path is not a directory")
ErrNotDirectory is the error returned when a directory is expected but not found.
Functions ¶
func AppendDataNewLine ¶
AppendDataNewLine appends data to a file, adding a newline at the end.
func AppendFile ¶
AppendFile appends data to a file with the specified mode.
func AreSemverVersionsValid ¶ added in v0.9.7
AreSemverVersionsValid checks one or more semver.Version pointers for validity. Returns the first error found, or nil if all are valid.
func CleanDirWithMkdirOption ¶
CleanDirWithMkdirOption validates and combines a directory path with the root directory.
func CleanDirsWithMkdirOption ¶
CleanDirsWithMkdirOption validates and combines a directory path with the root directory.
func CleanFilePathWithDirOption ¶
CleanFilePathWithDirOption combines a directory option with a partial path and cleans the result.
func CleanStringMap ¶ added in v0.9.7
CleanStringMap removes entries with empty keys or values from the given map. Trims all keys and values before checking.
func CleanStringSlice ¶ added in v0.9.7
CleanStringSlice removes empty or whitespace-only entries from the slice. Each string is trimmed before checking.
func CleanStringSliceToLower ¶ added in v0.9.8
CleanStringSliceToLower removes empty or whitespace-only entries from the slice, trims any space, and ensures characters are lower-case. Each string is trimmed before checking.
func CopyDir ¶
func CopyDir(src, dst string, opts ...CopyDirOpts) error
CopyDir recursively copies a directory tree, preserving permissions. Use opts to customize (e.g., ignore existing dest or add timestamp for backups).
func CopyFile ¶ added in v0.9.8
CopyFile copies a file from src to dst, setting permissions to PATH_CHMOD_FILE.
func CopyFileWithPerm ¶
func CopyFileWithPerm(srcPath, destPath string, doOverwrite bool, fileMode os.FileMode, includeNonRegularFiles bool) error
CopyFileWithPerm copies a file from srcPath to destPath with the specified permissions.
func CreateTempDir ¶
CreateTempDir creates a temporary directory with default options.
func CreateTempDirWithOptions ¶
func CreateTempDirWithOptions(options *TempDirOptions) (string, error)
CreateTempDirWithOptions creates a temporary directory with the specified options.
func DeleteDirectory ¶
func DeleteDirectory(dir string, dirCommonNameForErrorMessage string, deleteDirectory bool) (string, error)
DeleteDirectory deletes a directory if the deleteDirectory flag is true.
func DirectoryRecreate ¶
DirectoryRecreate removes and recreates a directory with the specified mode.
func EvaluateMockRootDir ¶ added in v0.9.7
EvaluateMockRootDir sets up the real RootDir based on a mock seed directory. - If DeleteMockRoot is true, RootDir will be forcefully wiped first. - If RootDir does not exist, MockRootDir will be copied into it.
func ExtractPlaceholderLeftRight ¶
func ExtractPlaceholderLeftRight(target string, left string, right string) (inner string, outer string)
ExtractPlaceholderLeftRight extracts content between left and right delimiters and the remaining string.
func ExtractPrefixBraces ¶
ExtractPrefixBraces extracts content within braces and the remaining string.
func ExtractPrefixBrackets ¶
ExtractPrefixBrackets extracts content within brackets and the remaining string.
func ExtractPrefixParenthesis ¶
ExtractPrefixParenthesis extracts content within parentheses and the remaining string.
func FileNameParts ¶
FileNameParts extracts the full name, name without extension, and extension from a file path.
func GetAppPath ¶
func GetAppPath(key AppPathKey) (string, bool)
GetAppPath retrieves a single path from the global sync.Map.
func GetFileNamePartExt ¶
GetFileNamePartExt extracts the extension from a file path. It handles multiple extensions (e.g., .tar.gz) and returns the full extension.
func GetFileNamePartExtNoDotPrefixToLower ¶
GetFileNamePartExtNoDotPrefixToLower extracts the extension from a file path, converts it to lowercase, and removes the dot prefix.
func GetFileNamePartName ¶
GetFileNamePartName extracts the file name without the extension from a file path.
func GetHighestSemverDirectory ¶
GetHighestSemverDirectory returns the directory path with the highest semantic version within the given directory.
func GetSystemLanguage ¶
GetSystemLanguage detects the system's language and locale based on the operating system. It returns the default language "en" and locale "US" if it cannot detect the system settings.
func HasAnyValidSemverVersion ¶ added in v0.9.7
HasAnyValidSemverVersion returns true if at least one provided version is valid.
func HasPrefixPath ¶
HasPrefixPath checks if the target string starts with any of the provided prefixes.
func IsDirEmpty ¶ added in v0.9.11
IsDirEmpty checks if the directory at the given path exists and contains no files or subdirectories. It returns true if the directory is empty, false if it exists but is not empty, and an error if the path does not exist or cannot be accessed.
func IsDirectory ¶
IsDirectory checks if the target is a directory.
func IsFileContentIdentical ¶
IsFileContentIdentical checks if the content of two files is identical.
func IsPathWithin ¶ added in v0.9.8
IsPathWithin returns true if target is the same as base or a descendant of base. Both base and target may be relative or absolute; they will be resolved to absolute paths. Symlinks are not resolved here; if you need that, wrap Abs with EvalSymlinks.
func IsSemverValid ¶ added in v0.9.7
IsSemverValid returns true if all provided semantic versions are valid.
func IsSemverVersionInvalid ¶
IsSemverVersionInvalid checks if the provided semantic version is invalid. Returns an error if version is nil, 0.0.0, or not greater than 0.0.0.
func IsUnderRoot ¶ added in v0.9.11
IsUnderRoot checks if the given path is under (or equal to) the root directory. It resolves both paths to absolute and checks if the relative path does not start with "..". Returns true if path is under root, false otherwise, and an error if resolution fails.
func ListFilenamesInDir ¶ added in v0.9.5
ListFilenamesInDir returns a list of filenames (not full paths) in the given directory.
func ListFilenamesInDirWithExtensions ¶ added in v0.9.5
ListFilenamesInDirWithExtensions returns a list of filenames (not full paths) in the given directory and filters them by the given extensions. If no extensions are passed, it returns all files.
func MoveFileWithPerm ¶
func MoveFileWithPerm(srcPath, destPath string, doOverwrite bool, fileMode os.FileMode, includeNonRegularFiles bool) error
MoveFileWithPerm copies a file from srcPath to destPath with the specified permissions, then deletes the srcPath.
func MustNewVersion ¶
MustNewVersion creates a new semantic version from a string, panicking if the string is not a valid semver.
func MustNewVersionPtr ¶ added in v0.9.7
MustNewVersionPtr creates a new semantic version from a string, panicking if the string is not a valid semver.
func NewNullUUIDWithValue ¶
NewNullUUIDWithValue creates a NullUUID with a new UUID version 7.
func NewUUIDAsString ¶
func NewUUIDAsString() string
NewUUIDAsString returns the string representation of a new UUID version 7.
func NewVersionFromString ¶
NewVersionFromString parses a semantic version from a string. Returns nil if parsing fails and doReturnNilElseUninitialized is true, otherwise returns an uninitialized version (0.0.0).
func ParseNullUUID ¶
ParseNullUUID parses a NullUUID from the given string.
func QuickBaseName ¶
QuickBaseName removes a single-dot extension from a file name.
func ReadByFilePathWithDirOption ¶
ReadByFilePathWithDirOption reads a file by combining a directory option with a partial path.
func ReadCSV ¶
func ReadCSV(csvReader *csv.Reader, headerLineCount int, fn FNReadCSVLine) error
ReadCSV processes CSV data from a *csv.Reader, handling headers and invoking a callback function for each line.
func ReadCSVFile ¶
func ReadCSVFile(fileCSV string, headerLineCount int, fn FNReadCSVLine) error
ReadCSVFile opens a CSV file and uses ReadCSV to process the file line by line.
func ReadFileTrimSpace ¶
ReadFileTrimSpace reads a file, trims the whitespace, and returns the content as a string.
func ReadFileTrimSpaceWithError ¶
ReadFileTrimSpaceWithError reads a file, trims the whitespace, and returns the content as a string along with an error if any.
func ResolveDirectory ¶
ResolveDirectory checks if the target is a directory and returns its clean path.
func ResolveFile ¶
ResolveFile checks if the target is a file and returns its clean path.
func SanitizeName ¶
SanitizeName ensures that a given string is safe for use as a file name and url. It performs the following operations: - Replaces spaces with dashes. - Removes invalid characters such as < > : " / \ | ? *. - Trims trailing dashes, periods, or whitespace. The resulting string is suitable for use in file systems and URLs.
func ScanFileByLine ¶
func ScanFileByLine(filePath string, fnScanLine FNScanLine) error
ScanFileByLine reads a file line by line and processes each line using the provided FNScanLine function.
func SetAppPath ¶
func SetAppPath(key AppPathKey, value string)
SetAppPath updates a single key in the global sync.Map.
func SetAppPathMap ¶
func SetAppPathMap(apm AppPathMap) error
SetAppPathMap initializes or updates the global AppPathMap.
func SetProcessUmask ¶ added in v0.9.7
func SetProcessUmask(umask int)
SetProcessUmask sets the process-wide file mode creation mask (umask).
The umask controls the default permission bits for **newly created files and directories** in the current process. It is **subtracted** from the default permissions requested by system calls like `os.Mkdir`, `os.Create`, or `net.Listen("unix")`.
Typical uses:
- ✅ Secure runtime temp files: Set `umask(0077)` so all created files/dirs are owner-only (`700` or `600`).
- ✅ Allow group collaboration: Set `umask(0027)` so files are owner+group accessible (`750` or `640`).
- ✅ Sockets: UNIX domain sockets inherit the umask — adjust to control who can connect.
**Example:** A daemon might tighten its umask early during `main()` to ensure any temp config, secrets, or IPC sockets are not accidentally world-readable.
Note: This affects only the **current process** and child processes that inherit the environment. It does **not** affect other processes.
For permanent system-wide behavior, the OS or container runtime usually sets the default umask.
func StringArrContainsString ¶
StringArrContainsString checks if a string slice contains a given string.
func StripExtensionPrefix ¶
StripExtensionPrefix removes the dot prefix from a file extension.
func ToStringTrimLower ¶
ToStringTrimLower returns the input string in lowercase after trimming whitespace.
func ToStringTrimUpper ¶
ToStringTrimUpper returns the input string in uppercase after trimming whitespace.
func UUIDToNullUUID ¶
UUIDToNullUUID converts a UUID to a NullUUID.
func UUIDToString ¶
UUIDToString returns the string representation of the given UUID. If the UUID is nil, it returns an empty string.
func UUIDToStringEmpty ¶
UUIDToStringEmpty is an alias for UUIDToString.
Types ¶
type AKey ¶
type AKey string
AKey is a structured string that: 1. Allows alpha A-Z, a-z, numbers 0-9, special characters (-_.) 2. Only alphas and numbers can begin or end the string 3. The period is the divider Derive your own custom "keys" from AKey, if desired.
func (AKey) MatchesOne ¶
MatchesOne checks if the AKey matches any one of the provided AKeys.
type AKeys ¶
type AKeys []AKey
AKeys is a slice of AKey.
func (AKeys) HasPrefix ¶
HasPrefix checks if any AKey in the slice has the provided AKey as a prefix.
func (AKeys) IncludeIfInTargets ¶
IncludeIfInTargets includes AKeys that match any of the target AKeys.
func (AKeys) ToArrStrings ¶
ToArrStrings converts the AKeys slice to a slice of strings.
type AppPathKey ¶
type AppPathKey string
AppPathKey is a custom type for application path keys.
const ( DIR_ROOT AppPathKey = "DIR_ROOT" DIR_ETC AppPathKey = "DIR_ETC" DIR_DATA AppPathKey = "DIR_DATA" DIR_LOGS AppPathKey = "DIR_LOGS" DIR_TMP_CACHE AppPathKey = "DIR_TMP_CACHE" DIR_WEBDISTRO AppPathKey = "DIR_WEBDISTRO" DIR_WEBDISTRO_PUBLIC AppPathKey = "DIR_WEBDISTRO_PUBLIC" DIR_WEBDISTRO_PROTED AppPathKey = "DIR_WEBDISTRO_PROTED" // short for PROTECTED DIR_WEBDISTRO_TEMPLATES AppPathKey = "DIR_WEBDISTRO_TEMPLATES" )
AppPathKey constants represent different directory keys for an application.
func (AppPathKey) IsDir ¶
func (key AppPathKey) IsDir() bool
IsDir checks if the AppPathKey represents a directory.
func (AppPathKey) IsEmpty ¶
func (key AppPathKey) IsEmpty() bool
IsEmpty checks if the AppPathKey is empty after trimming whitespace.
func (AppPathKey) IsFile ¶
func (key AppPathKey) IsFile() bool
IsFile checks if the AppPathKey represents a file.
func (AppPathKey) String ¶
func (key AppPathKey) String() string
String returns the string representation of the AppPathKey.
func (AppPathKey) ToStringTrimLower ¶
func (key AppPathKey) ToStringTrimLower() string
ToStringTrimLower trims whitespace and converts the AppPathKey to lowercase.
func (AppPathKey) TrimSpace ¶
func (key AppPathKey) TrimSpace() AppPathKey
TrimSpace trims leading and trailing whitespace from the AppPathKey.
func (AppPathKey) Type ¶
func (key AppPathKey) Type() string
Type extracts the type of path key, assuming it starts with 'dir' or 'file'.
type AppPathKeys ¶
type AppPathKeys []AppPathKey
type AppPathMap ¶
type AppPathMap map[AppPathKey]string
AppPathMap is a map that associates AppPathKeys with their path values.
func GetAppPathMap ¶
func GetAppPathMap() AppPathMap
GetAppPathMap retrieves the global AppPathMap as a copy.
func NewAppPathMap ¶ added in v0.9.7
func NewAppPathMap() AppPathMap
NewAppPathMap creates a new AppPathMap.
func (*AppPathMap) AutoSetupIfRootEmpty ¶ added in v0.9.11
func (apm *AppPathMap) AutoSetupIfRootEmpty(defaults AppPathMap) error
AutoSetupIfRootEmpty automatically sets up default paths and creates directories if DIR_ROOT is empty. It merges the provided defaults into the current AppPathMap (overrides win), resolves relative paths, and ensures all directories are created. If DIR_ROOT is not empty or does not exist, it skips setup. Defaults should use relative paths (e.g., "data" for DIR_DATA, "data/logs" for DIR_LOGS).
func (AppPathMap) Clone ¶ added in v0.9.7
func (m AppPathMap) Clone() AppPathMap
Clone returns a deep copy of the AppPathMap. It preserves all keys and values in a new map instance.
func (*AppPathMap) EnsureDirs ¶
func (apm *AppPathMap) EnsureDirs(dirRoot string) error
EnsureDirs ensures that all directories in the AppPathMap exist. It resolves relative paths using dirRoot before creation. Skips creation for paths that are not under dirRoot (if dirRoot is set).
func (AppPathMap) GetPath ¶
func (apm AppPathMap) GetPath(key AppPathKey) string
GetPath retrieves the path value associated with a given AppPathKey. If the key does not exist in the map, an empty string is returned.
func (*AppPathMap) IsRelative ¶ added in v0.9.7
func (apm *AppPathMap) IsRelative(key AppPathKey) bool
IsRelative checks if the path value associated with the given AppPathKey is a non-empty relative path. It returns true if the path is not empty and is not an absolute path. Returns false if the path is empty or already absolute.
func (AppPathMap) Merge ¶ added in v0.9.7
func (base AppPathMap) Merge(overrides ...AppPathMap) AppPathMap
Merge returns a new AppPathMap resulting from merging the current map (`base`) with one or more overrides. If a key exists in both, the override wins.
func (AppPathMap) MergeAbs ¶ added in v0.9.7
func (base AppPathMap) MergeAbs(baseDir string, overrides ...AppPathMap) AppPathMap
MergeAbs merges base paths with overrides, ensuring all resulting values are absolute. Any relative paths in the override will be joined with `baseDir`.
func (*AppPathMap) RecreateDir ¶
func (apm *AppPathMap) RecreateDir(key AppPathKey, mode os.FileMode) error
RecreateDir removes and recreates a directory for the specified AppPathKey with the given file mode. If the directory exists, it is deleted before being recreated. Returns an error if the path is missing or if any operation fails.
func (*AppPathMap) RequireWithOption ¶
func (apm *AppPathMap) RequireWithOption(dirRoot string, keys ...AppPathKey) error
RequireWithOption ensures that all specified AppPathKeys exist in the map. If dirRoot is empty, it attempts to retrieve DIR_ROOT from the map. Returns an error if any required key is missing or has an empty value.
func (*AppPathMap) ResolveAllRelatives ¶ added in v0.9.11
func (apm *AppPathMap) ResolveAllRelatives() error
ResolveAllRelatives resolves all relative paths in the AppPathMap to absolute paths using DIR_ROOT as the base directory. It mutates the map in place by updating relative path values to their absolute equivalents. If DIR_ROOT is not set, it returns an error. Empty or already absolute paths are skipped without changes.
func (*AppPathMap) SetPath ¶
func (apm *AppPathMap) SetPath(key AppPathKey, pathValue string)
SetPath sets the path value for a given AppPathKey.
func (*AppPathMap) SortedKeys ¶ added in v0.9.7
func (apm *AppPathMap) SortedKeys() []AppPathKey
SortedKeys returns the AppPathKeys in sorted order.
func (*AppPathMap) Validate ¶
func (apm *AppPathMap) Validate() error
Validate checks if the paths associated with the keys in the map exist. It returns an error if any path does not exist or cannot be resolved.
func (*AppPathMap) ValidateDir ¶ added in v0.9.8
func (apm *AppPathMap) ValidateDir() error
ValidateDir only checks those keys identified as a directory exist. It returns an error if any path does not exist or cannot be resolved.
func (*AppPathMap) ValidateWithOption ¶
func (apm *AppPathMap) ValidateWithOption(dirRoot string) error
ValidateWithOption validates the existence of paths in the AppPathMap. If dirRoot is an empty string, it attempts to retrieve it from the AppPathMap using DIR_ROOT. Relative paths are resolved using dirRoot before checking existence. If a relative path is modified, it updates the map with the absolute path.
type CopyDirFromTo ¶
CopyDirFromTo contains the "to" path "from" which data is to be copied,.
type CopyDirOpts ¶ added in v0.9.8
type CopyDirOpts struct {
IgnoreIfDestExists bool // If true, skip copy if dest exists
Timestamp string // Optional timestamp suffix for dest (e.g., "20060102-150405"); empty means no suffix
}
CopyDirOpts holds options for CopyDir.
type CopyDirsFromTo ¶
type CopyDirsFromTo []*CopyDirFromTo
CopyDirsFromTo contains a slice of CopyDirFromTo structs for copying multiple directories.
func (CopyDirsFromTo) RunCopy ¶
func (c CopyDirsFromTo) RunCopy() error
RunCopy performs the copying of directories as specified in CopyDirsFromTo.
type FNReadCSVLine ¶
type FNReadCSVLine func(headers map[int][]string, lineOn int, line []string) (doStop bool, err error)
FNReadCSVLine is a function type that processes a line from a CSV file. It takes a map of headers, the current line number, and the line content. It returns a boolean indicating whether to stop reading the CSV and any error encountered.
type FNScanLine ¶
FNScanLine is a function type for processing a line of text.
type LanguageType ¶
type LanguageType string
LanguageType represents a language code following the IETF BCP 47 standard.
func GetHTTPAcceptedLanguage ¶
func GetHTTPAcceptedLanguage(target string) LanguageType
GetHTTPAcceptedLanguage parses the Accept-Language header to extract the language preference.
func GetHTTPAcceptedLanguageWithDefault ¶
func GetHTTPAcceptedLanguageWithDefault(target string, altDefault LanguageType) LanguageType
GetHTTPAcceptedLanguageWithDefault parses the Accept-Language header and returns the language preference, falling back to a default if necessary.
func GetSystemLanguageType ¶
func GetSystemLanguageType() LanguageType
GetSystemLanguageType retrieves the system language and locale in the format "language-locale". If only the language is available, it returns "language". If neither is available, it returns an empty string.
func (LanguageType) GetLanguage ¶
func (lant LanguageType) GetLanguage() string
GetLanguage extracts the language part from the LanguageType.
func (LanguageType) GetLocale ¶
func (lant LanguageType) GetLocale() string
GetLocale extracts the locale part from the LanguageType.
func (LanguageType) GetParts ¶
func (lant LanguageType) GetParts() (lang string, locale string)
GetParts splits the LanguageType into its language and locale components.
func (LanguageType) IsEmpty ¶
func (lant LanguageType) IsEmpty() bool
IsEmpty checks if the LanguageType is empty after trimming whitespace.
func (LanguageType) String ¶
func (lant LanguageType) String() string
String returns the string representation of the LanguageType.
func (LanguageType) TrimSpace ¶
func (lant LanguageType) TrimSpace() LanguageType
TrimSpace returns a new LanguageType with leading and trailing whitespace removed.
type NullUUIDs ¶
NullUUIDs is a slice of NullUUIDs.
func (NullUUIDs) ValidateWithOptions ¶
ValidateWithOptions checks if all NullUUIDs in the slice are non-nil. If mustHaveCount is true, it also checks that the slice is not empty.
type Semver ¶
type Semver struct {
Version semver.Version `json:"version"` // Version follows semantic versioning.
Directory string `json:"directory,omitempty"` // Directory where the version is stored (if applicable).
Tag string `json:"tag,omitempty"` // Tag associated with the version (alternative to Directory).
}
Semver represents a semantic versioning information with optional directory and tag.
type Semvers ¶
type Semvers []*Semver
Semvers is a slice of pointers to Semver, representing a collection of semantic versions.
func NewSemverListFromDirectory ¶
NewSemverListFromDirectory creates a Semvers slice from the directory names within the given directory.
func NewSemverListFromStrings ¶
NewSemverListFromStrings creates a Semvers slice from a list of version strings.
type StringsArray ¶
type StringsArray []string
StringsArray is a custom type that extends []string. It provides a custom unmarshaling from JSON to handle both an array of strings and a single comma-delimited string.
func (*StringsArray) UnmarshalJSON ¶
func (sa *StringsArray) UnmarshalJSON(b []byte) error
UnmarshalJSON is a custom unmarshaller for StringsArray. It supports unmarshaling from both an array of strings in JSON and a single comma-separated string.
type TempDirOptions ¶
type TempDirOptions struct {
DirRoot string // Root directory for the temp dir, defaults to the system temp dir if empty.
Name string // Name of the temp dir, auto-created as "tmp-UUID" if empty.
AppendUUIDv4 bool // If true and name is not empty, then append "-UUID" to the name.
}
TempDirOptions defines options for creating temporary directories.
type UUIDs ¶
UUIDs is a slice of UUIDs.
func (UUIDs) ValidateWithOptions ¶
ValidateWithOptions checks if all UUIDs in the slice are non-nil. If mustHaveCount is true, it also checks that the slice is not empty.