autils

package
v0.9.12 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: Apache-2.0 Imports: 21 Imported by: 9

Documentation

Index

Constants

View Source
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

View Source
var ErrEmptyPath = errors.New("file path is empty")

ErrEmptyPath indicates that the file path provided is empty.

View Source
var ErrFileNotResolved = errors.New("file could not be resolved")

ErrFileNotResolved indicates that the file could not be resolved.

View Source
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

func AppendDataNewLine(path string, data []byte, fileMode os.FileMode) error

AppendDataNewLine appends data to a file, adding a newline at the end.

func AppendFile

func AppendFile(filepath string, data []byte, mode os.FileMode) error

AppendFile appends data to a file with the specified mode.

func AreSemverVersionsValid added in v0.9.7

func AreSemverVersionsValid(versions ...*semver.Version) error

AreSemverVersionsValid checks one or more semver.Version pointers for validity. Returns the first error found, or nil if all are valid.

func CleanDirWithMkdirOption

func CleanDirWithMkdirOption(dir, root string, doMkDir bool) (string, error)

CleanDirWithMkdirOption validates and combines a directory path with the root directory.

func CleanDirsWithMkdirOption

func CleanDirsWithMkdirOption(dirList []string, root string, doMkDir bool) error

CleanDirsWithMkdirOption validates and combines a directory path with the root directory.

func CleanFilePathWithDirOption

func CleanFilePathWithDirOption(targetPathAbsOrPartial string, dirOption string) (string, error)

CleanFilePathWithDirOption combines a directory option with a partial path and cleans the result.

func CleanStringMap added in v0.9.7

func CleanStringMap(m map[string]string) map[string]string

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

func CleanStringSlice(input []string) []string

CleanStringSlice removes empty or whitespace-only entries from the slice. Each string is trimmed before checking.

func CleanStringSliceToLower added in v0.9.8

func CleanStringSliceToLower(input []string) []string

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

func CopyFile(src, dst string) error

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

func CreateTempDir() (string, error)

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 DirExists

func DirExists(dir string) bool

DirExists checks if the given directory exists.

func DirectoryRecreate

func DirectoryRecreate(dir string, mode os.FileMode) error

DirectoryRecreate removes and recreates a directory with the specified mode.

func EvaluateMockRootDir added in v0.9.7

func EvaluateMockRootDir(mockDir string, rootDir string, deleteRoot bool) error

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 Exists

func Exists(target string) bool

Exists checks if the given path exists.

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

func ExtractPrefixBraces(target string) (inner string, outer string)

ExtractPrefixBraces extracts content within braces and the remaining string.

func ExtractPrefixBrackets

func ExtractPrefixBrackets(target string) (inner string, outer string)

ExtractPrefixBrackets extracts content within brackets and the remaining string.

func ExtractPrefixParenthesis

func ExtractPrefixParenthesis(target string) (inner string, outer string)

ExtractPrefixParenthesis extracts content within parentheses and the remaining string.

func FileExists

func FileExists(filename string) bool

FileExists checks if the given file exists.

func FileNameParts

func FileNameParts(target string) (fullname, name, ext string)

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

func GetFileNamePartExt(target string) (ext string)

GetFileNamePartExt extracts the extension from a file path. It handles multiple extensions (e.g., .tar.gz) and returns the full extension.

func GetFileNamePartExtNoDotPrefixToLower

func GetFileNamePartExtNoDotPrefixToLower(target string) (ext string)

GetFileNamePartExtNoDotPrefixToLower extracts the extension from a file path, converts it to lowercase, and removes the dot prefix.

func GetFileNamePartName

func GetFileNamePartName(target string) (name string)

GetFileNamePartName extracts the file name without the extension from a file path.

func GetHighestSemverDirectory

func GetHighestSemverDirectory(dir string) (string, error)

GetHighestSemverDirectory returns the directory path with the highest semantic version within the given directory.

func GetSystemLanguage

func GetSystemLanguage() (lang string, locale string)

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

func HasAnyValidSemverVersion(versions ...*semver.Version) bool

HasAnyValidSemverVersion returns true if at least one provided version is valid.

func HasPrefixPath

func HasPrefixPath(target string, prefixPaths []string) bool

HasPrefixPath checks if the target string starts with any of the provided prefixes.

func IsDirEmpty added in v0.9.11

func IsDirEmpty(path string) (bool, error)

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

func IsDirectory(target string) (bool, error)

IsDirectory checks if the target is a directory.

func IsFile

func IsFile(target string) (bool, error)

IsFile checks if the target is a file.

func IsFileContentIdentical

func IsFileContentIdentical(file1 string, file2 string) (bool, error)

IsFileContentIdentical checks if the content of two files is identical.

func IsPathWithin added in v0.9.8

func IsPathWithin(base, target string) (bool, error)

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

func IsSemverValid(version ...*semver.Version) bool

IsSemverValid returns true if all provided semantic versions are valid.

func IsSemverVersionInvalid

func IsSemverVersionInvalid(version *semver.Version) error

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

func IsUnderRoot(root, path string) (bool, error)

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

func ListFilenamesInDir(dirPath string) []string

ListFilenamesInDir returns a list of filenames (not full paths) in the given directory.

func ListFilenamesInDirWithExtensions added in v0.9.5

func ListFilenamesInDirWithExtensions(dirPath string, exts ...string) []string

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 MergeMaps

func MergeMaps(maps ...map[string]string) map[string]string

MergeMaps merges multiple map[string]string maps.

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

func MustNewVersion(version string) semver.Version

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

func MustNewVersionPtr(version string) *semver.Version

MustNewVersionPtr creates a new semantic version from a string, panicking if the string is not a valid semver.

func NewNullUUIDWithValue

func NewNullUUIDWithValue() uuid.NullUUID

NewNullUUIDWithValue creates a NullUUID with a new UUID version 7.

func NewUUID

func NewUUID() uuid.UUID

NewUUID generates a new UUID version 7 and returns it.

func NewUUIDAsString

func NewUUIDAsString() string

NewUUIDAsString returns the string representation of a new UUID version 7.

func NewVersionFromString

func NewVersionFromString(version string, doReturnNilElseUninitialized bool) *semver.Version

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

func ParseNullUUID(target string) uuid.NullUUID

ParseNullUUID parses a NullUUID from the given string.

func ParseUUID

func ParseUUID(target string) uuid.UUID

ParseUUID parses a UUID from the given string.

func QuickBaseName

func QuickBaseName(s string) string

QuickBaseName removes a single-dot extension from a file name.

func ReadByFilePathWithDirOption

func ReadByFilePathWithDirOption(targetPathAbsOrPartial string, dirOption string) ([]byte, error)

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

func ReadFileTrimSpace(filePath string) string

ReadFileTrimSpace reads a file, trims the whitespace, and returns the content as a string.

func ReadFileTrimSpaceWithError

func ReadFileTrimSpaceWithError(filePath string) (string, error)

ReadFileTrimSpaceWithError reads a file, trims the whitespace, and returns the content as a string along with an error if any.

func ResolveDirectory

func ResolveDirectory(target string) (string, error)

ResolveDirectory checks if the target is a directory and returns its clean path.

func ResolveFile

func ResolveFile(target string) (string, error)

ResolveFile checks if the target is a file and returns its clean path.

func SanitizeName

func SanitizeName(name string) string

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

func StringArrContainsString(slice []string, item string) bool

StringArrContainsString checks if a string slice contains a given string.

func StripExtensionPrefix

func StripExtensionPrefix(input string) string

StripExtensionPrefix removes the dot prefix from a file extension.

func ToStringTrimLower

func ToStringTrimLower(target string) string

ToStringTrimLower returns the input string in lowercase after trimming whitespace.

func ToStringTrimUpper

func ToStringTrimUpper(target string) string

ToStringTrimUpper returns the input string in uppercase after trimming whitespace.

func UUIDToNullUUID

func UUIDToNullUUID(target uuid.UUID) uuid.NullUUID

UUIDToNullUUID converts a UUID to a NullUUID.

func UUIDToString

func UUIDToString(target uuid.UUID) string

UUIDToString returns the string representation of the given UUID. If the UUID is nil, it returns an empty string.

func UUIDToStringEmpty

func UUIDToStringEmpty(target uuid.UUID) string

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) HasMatch

func (rt AKey) HasMatch(rtType AKey) bool

HasMatch checks if the AKey matches the provided AKey.

func (AKey) HasPrefix

func (rt AKey) HasPrefix(rtType AKey) bool

HasPrefix checks if the AKey has the provided AKey as a prefix.

func (AKey) HasSuffix

func (rt AKey) HasSuffix(rtType AKey) bool

HasSuffix checks if the AKey has the provided AKey as a suffix.

func (AKey) IsEmpty

func (rt AKey) IsEmpty() bool

IsEmpty checks if the AKey is empty after trimming space.

func (AKey) MatchesOne

func (rt AKey) MatchesOne(rtTypes ...AKey) bool

MatchesOne checks if the AKey matches any one of the provided AKeys.

func (AKey) String

func (rt AKey) String() string

String returns the string representation of AKey.

func (AKey) TrimSpace

func (rt AKey) TrimSpace() AKey

TrimSpace trims leading and trailing white spaces from AKey.

func (AKey) Validate

func (rt AKey) Validate() error

Validate checks if the AKey is valid according to the rules.

type AKeys

type AKeys []AKey

AKeys is a slice of AKey.

func (AKeys) Clean

func (rts AKeys) Clean() AKeys

Clean removes empty AKeys from the slice.

func (AKeys) Clone

func (rts AKeys) Clone() AKeys

Clone creates a copy of the AKeys slice.

func (AKeys) HasMatch

func (rts AKeys) HasMatch(rType AKey) bool

HasMatch checks if any AKey in the slice matches the provided AKey.

func (AKeys) HasPrefix

func (rts AKeys) HasPrefix(rType AKey) bool

HasPrefix checks if any AKey in the slice has the provided AKey as a prefix.

func (AKeys) HasValues

func (rts AKeys) HasValues() bool

HasValues checks if the AKeys slice has any values.

func (AKeys) IncludeIfInTargets

func (rts AKeys) IncludeIfInTargets(targets AKeys) AKeys

IncludeIfInTargets includes AKeys that match any of the target AKeys.

func (AKeys) ToArrStrings

func (rts AKeys) ToArrStrings() []string

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

type CopyDirFromTo struct {
	From string `json:"from"`
	To   string `json:"to"`
}

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

type FNScanLine func(string) error

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

type NullUUIDs []uuid.NullUUID

NullUUIDs is a slice of NullUUIDs.

func (NullUUIDs) Clean

func (ids NullUUIDs) Clean() NullUUIDs

Clean returns a new slice with nil NullUUIDs removed.

func (NullUUIDs) Has

func (ids NullUUIDs) Has(target uuid.UUID) bool

Has checks if the slice contains the target NullUUID.

func (NullUUIDs) Validate

func (ids NullUUIDs) Validate() error

Validate checks if all NullUUIDs in the slice are non-nil.

func (NullUUIDs) ValidateWithOptions

func (ids NullUUIDs) ValidateWithOptions(mustHaveCount bool) error

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.

func NewSemver

func NewSemver(version *semver.Version, directory string, tag string) *Semver

NewSemver creates a new Semver instance with the provided version, directory, and tag.

type Semvers

type Semvers []*Semver

Semvers is a slice of pointers to Semver, representing a collection of semantic versions.

func NewSemverListFromDirectory

func NewSemverListFromDirectory(dir string) (Semvers, error)

NewSemverListFromDirectory creates a Semvers slice from the directory names within the given directory.

func NewSemverListFromStrings

func NewSemverListFromStrings(versions []string) (Semvers, error)

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

type UUIDs []uuid.UUID

UUIDs is a slice of UUIDs.

func (UUIDs) Clean

func (ids UUIDs) Clean() UUIDs

Clean returns a new slice with duplicate and nil UUIDs removed.

func (UUIDs) Has

func (ids UUIDs) Has(target uuid.UUID) bool

Has checks if the slice contains the target UUID.

func (UUIDs) Validate

func (ids UUIDs) Validate() error

Validate checks if all UUIDs in the slice are non-nil.

func (UUIDs) ValidateWithOptions

func (ids UUIDs) ValidateWithOptions(mustHaveCount bool) error

ValidateWithOptions checks if all UUIDs in the slice are non-nil. If mustHaveCount is true, it also checks that the slice is not empty.

Jump to

Keyboard shortcuts

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