Documentation
¶
Index ¶
- Variables
- func AppendErr(errs []error, err error) []error
- func CanWrite(path EntryPath) (canWrite bool, err error)
- func ChangeDirTimes(dp DirPath, atime time.Time, mtime time.Time) error
- func ChangeFileTimes(fp Filepath, atime time.Time, mtime time.Time) error
- func Chtimes[T ~string](path T, atime time.Time, mtime time.Time) error
- func CloseOrLog(c io.Closer)
- func CombineErrs(errs []error) error
- func CreateFile(fp Filepath) (*os.File, error)
- func CreateTemp(dp DirPath, pattern string) (*os.File, error)
- func DirFS(dp DirPath) fs.FS
- func EnsureLogger() *slog.Logger
- func ErrValue[T any](err error, key string) (T, bool)
- func Errors(err error) []error
- func FSReadFile(fileSys fs.FS, fp Filepath) ([]byte, error)
- func FSStat[T ~string](fileSys fs.FS, entry T) (fs.FileInfo, error)
- func FSStatDir(fileSys fs.FS, dp DirPath) (fs.FileInfo, error)
- func FSStatFile(fileSys fs.FS, fp Filepath) (fs.FileInfo, error)
- func FindErr[T error](err error) (out T, ok bool)
- func IndexSegments[S ~string](s, sep string, index int) S
- func JoinSegments[S ~string](ss []S, sep string) (s S)
- func LogOnError(err error)
- func Logger() *slog.Logger
- func MkdirAll(dp DirPath, mode os.FileMode) error
- func MsgErr(msg any) error
- func NewErr(parts ...any) error
- func ParseTimeDurationEx(s string) (td time.Duration, err error)
- func ReadFile(fp Filepath) ([]byte, error)
- func RemoveAll(dp DirPath) error
- func SetLogger(l *slog.Logger)
- func SliceSegments[S ~string](s, sep string, start, end int) []S
- func SliceSegmentsScalar[S ~string](s, sep string, start, end int) S
- func SplitSegments[S ~string](s, sep string) []S
- func Stat[T ~string](entry T) (os.FileInfo, error)
- func StatDir(dp DirPath) (os.FileInfo, error)
- func StatFile(fp Filepath) (os.FileInfo, error)
- func UnixModeFunc(ep EntryPath) (mode os.FileMode)
- func WalkDir(root DirPath) iter.Seq2[DirEntry, error]
- func WithErr(parts ...any) error
- func WriteFile(fp Filepath, data []byte, mode os.FileMode) error
- type Config
- type CopyOptions
- type DirEntry
- func (de DirEntry) Base() EntryPath
- func (de DirEntry) DirPath() DirPath
- func (de DirEntry) EntryPath() EntryPath
- func (de DirEntry) Ext() FileExt
- func (de DirEntry) Filename() Filename
- func (de DirEntry) Filepath() Filepath
- func (de DirEntry) IsDir() (isDir bool)
- func (de DirEntry) IsFile() (isFile bool)
- func (de DirEntry) PathSegment() PathSegment
- func (de DirEntry) SkipDir()
- type DirPath
- func DirPathJoin[T1, T2 ~string](a T1, b T2) DirPath
- func DirPathJoin3[T1, T2, T3 ~string](a T1, b T2, c T3) DirPath
- func DirPathJoin4[T1, T2, T3, T4 ~string](a T1, b T2, c T3, d T4) DirPath
- func DirPathJoin5[T1, T2, T3, T4, T5 ~string](a T1, b T2, c T3, d T4, e T5) DirPath
- func Getwd() (DirPath, error)
- func MkdirTemp(dp DirPath, pattern string) (DirPath, error)
- func ParseDirPath(s string) (dp DirPath, err error)
- func ParseDirPaths(dirs []string) (dps []DirPath, err error)
- func TempDir() DirPath
- func UserCacheDir() (DirPath, error)
- func UserConfigDir() (DirPath, error)
- func UserHomeDir() (DirPath, error)
- func (dp DirPath) Abs() (DirPath, error)
- func (dp DirPath) Base() PathSegment
- func (dp DirPath) CanWrite() (bool, error)
- func (dp DirPath) Chmod(mode os.FileMode) error
- func (dp DirPath) Clean() DirPath
- func (dp DirPath) Contains(part any) bool
- func (dp DirPath) Dir() DirPath
- func (dp DirPath) DirFS() fs.FS
- func (dp DirPath) EnsureExists() (err error)
- func (dp DirPath) EnsureTrailSep() DirPath
- func (dp DirPath) ErrKV() ErrKV
- func (dp DirPath) EvalSymlinks() (_ DirPath, err error)
- func (dp DirPath) Exists() (exists bool, err error)
- func (dp DirPath) Expand() (_ DirPath, err error)
- func (dp DirPath) HasDotDotPrefix() bool
- func (dp DirPath) HasPrefix(prefix DirPath) bool
- func (dp DirPath) HasSuffix(suffix string) bool
- func (dp DirPath) IsAbs() bool
- func (dp DirPath) IsTidlePath() bool
- func (dp DirPath) Join(elems ...any) DirPath
- func (dp DirPath) Lstat(fileSys ...fs.FS) (os.FileInfo, error)
- func (dp DirPath) MkdirAll(mode os.FileMode) error
- func (dp DirPath) Normalize() (DirPath, error)
- func (dp DirPath) ReadDir() ([]os.DirEntry, error)
- func (dp DirPath) Rel(baseDir DirPath) (PathSegments, error)
- func (dp DirPath) Remove() error
- func (dp DirPath) RemoveAll() error
- func (dp DirPath) Stat(fileSys ...fs.FS) (os.FileInfo, error)
- func (dp DirPath) Status(flags ...EntryStatusFlags) (status EntryStatus, err error)
- func (dp DirPath) String() string
- func (dp DirPath) ToLower() DirPath
- func (dp DirPath) ToSlash() DirPath
- func (dp DirPath) ToTilde() (tdp TildeDirPath, err error)
- func (dp DirPath) ToUpper() DirPath
- func (dp DirPath) TrimPrefix(prefix DirPath) DirPath
- func (dp DirPath) TrimSuffix(TrimSuffix string) DirPath
- func (dp DirPath) VolumeName() VolumeName
- func (dp DirPath) Walk() iter.Seq2[DirEntry, error]
- func (dp DirPath) WalkDirs() iter.Seq2[DirEntry, error]
- func (dp DirPath) WalkDirsFS(fsys fs.FS) iter.Seq2[DirEntry, error]
- func (dp DirPath) WalkFS(fsys fs.FS) iter.Seq2[DirEntry, error]
- func (dp DirPath) WalkFiles() iter.Seq2[DirEntry, error]
- func (dp DirPath) WalkFilesFS(fsys fs.FS) iter.Seq2[DirEntry, error]
- type EntryModeFunc
- type EntryPath
- func (ep EntryPath) Abs() (EntryPath, error)
- func (ep EntryPath) Base() PathSegment
- func (ep EntryPath) Clean() EntryPath
- func (ep EntryPath) Contains(substr any) bool
- func (ep EntryPath) Dir() DirPath
- func (ep EntryPath) EnsureTrailSep() EntryPath
- func (ep EntryPath) EvalSymlinks() (_ EntryPath, err error)
- func (ep EntryPath) Expand() (out EntryPath, err error)
- func (ep EntryPath) HasDotDotPrefix() bool
- func (ep EntryPath) HasSuffix(suffix DirPath) bool
- func (ep EntryPath) IsAbs() bool
- func (ep EntryPath) IsFile() bool
- func (ep EntryPath) Join(elems ...any) EntryPath
- func (ep EntryPath) Lstat(fileSys ...fs.FS) (os.FileInfo, error)
- func (ep EntryPath) Readlink() (target EntryPath, err error)
- func (ep EntryPath) Stat(fileSys ...fs.FS) (fs.FileInfo, error)
- func (ep EntryPath) Status(flags ...EntryStatusFlags) (status EntryStatus, err error)
- func (ep EntryPath) VolumeName() VolumeName
- type EntryStatus
- type EntryStatusFlags
- type ErrKV
- func AnyKV(key string, value any) ErrKV
- func AppendKV(kvs []ErrKV, parts ...any) []ErrKV
- func BoolKV(key string, value bool) ErrKV
- func ErrMeta(err error) []ErrKV
- func ErrorKV(key string, value error) ErrKV
- func Float64KV(key string, value float64) ErrKV
- func Int64KV(key string, value int64) ErrKV
- func IntKV(key string, value int) ErrKV
- func StringKV(key, value string) ErrKV
- type FileExt
- type Filename
- type Filepath
- func FilepathJoin[T1, T2 ~string](a T1, b T2) Filepath
- func FilepathJoin3[T1, T2, T3 ~string](a T1, b T2, c T3) Filepath
- func FilepathJoin4[T1, T2, T3, T4 ~string](a T1, b T2, c T3, d T4) Filepath
- func FilepathJoin5[T1, T2, T3, T4, T5 ~string](a T1, b T2, c T3, d T4, e T5) Filepath
- func ParseFilepath(s string) (fp Filepath, err error)
- func (fp Filepath) Abs() (Filepath, error)
- func (fp Filepath) Base() Filename
- func (fp Filepath) CopyTo(dest Filepath, opts *CopyOptions) (err error)
- func (fp Filepath) CopyToDir(dest DirPath, opts *CopyOptions) (err error)
- func (fp Filepath) Create() (*os.File, error)
- func (fp Filepath) Dir() DirPath
- func (fp Filepath) EvalSymlinks() (_ Filepath, err error)
- func (fp Filepath) Exists() (exists bool, err error)
- func (fp Filepath) Expand() (_ Filepath, err error)
- func (fp Filepath) Ext() FileExt
- func (fp Filepath) HasDotDotPrefix() bool
- func (fp Filepath) HasPrefix(prefix DirPath) bool
- func (fp Filepath) HasSuffix(suffix DirPath) bool
- func (fp Filepath) Join(elems ...any) Filepath
- func (fp Filepath) Lstat() (os.FileInfo, error)
- func (fp Filepath) Open() (*os.File, error)
- func (fp Filepath) OpenFile(flag int, mode os.FileMode) (*os.File, error)
- func (fp Filepath) ReadFile(fileSys ...fs.FS) ([]byte, error)
- func (fp Filepath) Readlink() (target Filepath, err error)
- func (fp Filepath) Rel(baseDir DirPath) (RelFilepath, error)
- func (fp Filepath) Remove() error
- func (fp Filepath) Stat(fileSys ...fs.FS) (os.FileInfo, error)
- func (fp Filepath) Status(flags ...EntryStatusFlags) (status EntryStatus, err error)
- func (Filepath) StringLike()
- func (fp Filepath) ValidPath() bool
- func (fp Filepath) WriteFile(data []byte, mode os.FileMode) error
- type FilepathGetter
- type Identifier
- type InternetDomain
- type PathSegment
- func (ps PathSegment) Contains(part any) bool
- func (ps PathSegment) Exists() (exists bool, err error)
- func (ps PathSegment) HasDotDotPrefix() bool
- func (ps PathSegment) MkdirAll(mode os.FileMode) error
- func (ps PathSegment) Status(flags ...EntryStatusFlags) (status EntryStatus, err error)
- func (ps PathSegment) TrimPrefix(prefix DirPath) PathSegment
- func (ps PathSegment) TrimSuffix(TrimSuffix string) PathSegment
- func (ps PathSegment) WriteFile(data []byte, mode os.FileMode) error
- type PathSegments
- func ParentPath() PathSegments
- func PathSegmentsJoin[T1, T2 ~string](a T1, b T2) PathSegments
- func PathSegmentsJoin3[T1, T2, T3 ~string](a T1, b T2, c T3) PathSegments
- func PathSegmentsJoin4[T1, T2, T3, T4 ~string](a T1, b T2, c T3, d T4) PathSegments
- func PathSegmentsJoin5[T1, T2, T3, T4, T5 ~string](a T1, b T2, c T3, d T4, e T5) PathSegments
- func (pss PathSegments) Contains(part any) bool
- func (pss PathSegments) Escapes() (escapes bool)
- func (pss PathSegments) FromSlash() PathSegments
- func (pss PathSegments) HasPrefix(prefix PathSegments) bool
- func (pss PathSegments) HasSuffix(suffix string) bool
- func (pss PathSegments) LastIndex(sep string) int
- func (pss PathSegments) Normalize() PathSegments
- func (pss PathSegments) Segment(index int) PathSegment
- func (pss PathSegments) Segments() []PathSegment
- func (pss PathSegments) Slice(start, end int) []PathSegment
- func (pss PathSegments) SliceScalar(start, end int) PathSegments
- func (pss PathSegments) Split() []PathSegment
- func (pss PathSegments) ToLower() PathSegments
- func (pss PathSegments) ToSlash() PathSegments
- func (pss PathSegments) ToUpper() PathSegments
- func (pss PathSegments) TrimPrefix(prefix PathSegments) PathSegments
- func (pss PathSegments) TrimSpace() PathSegments
- func (pss PathSegments) TrimSuffix(TrimSuffix string) PathSegments
- func (pss PathSegments) UpperFirst() PathSegments
- type RelDirPath
- type RelFilepath
- func RelFilepathJoin[T1, T2 ~string](a T1, b T2) RelFilepath
- func RelFilepathJoin3[T1, T2, T3 ~string](a T1, b T2, c T3) RelFilepath
- func RelFilepathJoin4[T1, T2, T3, T4 ~string](a T1, b T2, c T3, d T4) RelFilepath
- func RelFilepathJoin5[T1, T2, T3, T4, T5 ~string](a T1, b T2, c T3, d T4, e T5) RelFilepath
- func (fp RelFilepath) Base() Filename
- func (fp RelFilepath) Dir() DirPath
- func (fp RelFilepath) Exists() (exists bool, err error)
- func (fp RelFilepath) ReadFile(fileSys ...fs.FS) ([]byte, error)
- func (fp RelFilepath) Rel(baseDir DirPath) (RelFilepath, error)
- func (fp RelFilepath) Stat(fileSys ...fs.FS) (os.FileInfo, error)
- func (fp RelFilepath) Status(flags ...EntryStatusFlags) (status EntryStatus, err error)
- func (fp RelFilepath) ValidPath() bool
- func (fp RelFilepath) WriteFile(data []byte, mode os.FileMode) error
- type RelPath
- func (rp RelPath) Abs() (RelPath, error)
- func (rp RelPath) Base() PathSegment
- func (rp RelPath) Contains(substr any) bool
- func (rp RelPath) Dir() DirPath
- func (rp RelPath) HasSuffix(suffix DirPath) bool
- func (rp RelPath) Join(elems ...any) RelPath
- func (rp RelPath) Lstat() (os.FileInfo, error)
- func (rp RelPath) Readlink() (target RelPath, err error)
- func (rp RelPath) Stat(fileSys ...fs.FS) (fs.FileInfo, error)
- func (rp RelPath) Status(flags ...EntryStatusFlags) (status EntryStatus, err error)
- func (rp RelPath) VolumeName() VolumeName
- type TildeDirPath
- type TimeFormat
- type URL
- type URLSegment
- type URLSegments
- func ParseURLSegments(s string) (uss URLSegments, err error)
- func URLSegmentsJoin[T1, T2 ~string](a T1, b T2) URLSegments
- func URLSegmentsJoin3[T1, T2, T3 ~string](a T1, b T2, c T3) URLSegments
- func URLSegmentsJoin4[T1, T2, T3, T4 ~string](a T1, b T2, c T3, d T4) URLSegments
- func URLSegmentsJoin5[T1, T2, T3, T4, T5 ~string](a T1, b T2, c T3, d T4, e T5) URLSegments
- func (uss URLSegments) Base() URLSegment
- func (uss URLSegments) LastIndex(sep string) int
- func (uss URLSegments) Segment(index int) URLSegment
- func (uss URLSegments) Segments() []URLSegment
- func (uss URLSegments) Slice(start, end int) []URLSegment
- func (uss URLSegments) SliceScalar(start, end int, sep string) URLSegment
- func (uss URLSegments) Split() []URLSegment
- type Version
- type VolumeName
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingSentinel = errors.New("missing required sentinel error") ErrTrailingKey = errors.New("trailing key without value") ErrMisplacedError = errors.New("error in wrong position") ErrInvalidArgumentType = errors.New("invalid argument type") ErrOddKeyValueCount = errors.New("odd number of key-value arguments") ErrCrossPackageError = errors.New("error from different doterr package") )
Sentinel errors for validation failures
var ( ErrPathIsDir = errors.New("path is a directory") ErrPathIsFile = errors.New("path is a file (not a directory)") ErrDoesNotExist = errors.New("does not exist") ErrExists = errors.New("exists") ErrDirDoesNotExist = errors.New("dir does not exist") ErrDirExists = errors.New("dir exists") ErrFileNotExists = errors.New("file does not exist") ErrFileExists = errors.New("file exists") ErrInvalidEntryStatus = errors.New("invalid entry status") ErrUnclassifiedEntryStatus = errors.New("unclassified entry status") ErrUnsupportedEntryType = errors.New("unsupported entry type") )
var ( ErrInvalidPathSegment = errors.New("invalid path segment") ErrInvalidURLSegment = errors.New("invalid URL segment") ErrInvalidURLSegments = errors.New("invalid URL segments") ErrInvalidIdentifier = errors.New("invalid identifier") ErrFailedTypeAssertion = errors.New("failed type assertion") // ErrInvalidForOpen is used when ValidPath()==false ErrInvalidForOpen = errors.New("invalid for open") )
var ( ErrFileSystem = errors.New("file system error") ErrFailedReadingSymlink = errors.New("failed reading symlink") ErrFailedToLoadFile = errors.New("failed to load file") ErrFailedToCopyFile = errors.New("failed to copy file") ErrFailedToMakeDirectory = errors.New("failed to make directory") ErrFailedtoCreateTempFile = errors.New("failed to create temp file") ErrFailedtoCreateFile = errors.New("failed to create file") ErrContainsBackslash = errors.New("contains slash ('\\')") ErrContainsSlash = errors.New("contains slash ('/')") ErrEmpty = errors.New("cannot be empty") ErrInvalidPercentEncoding = errors.New("invalid percent encoding") ErrTooLong = errors.New("too long") ErrUnspecified = errors.New("unspecified") ErrInvalid = errors.New("invalid") ErrInvalidDirectory = errors.New("invalid directory") ErrInvalidfileSystemEntryType = errors.New("invalid file system entry type") ErrControlCharacter = errors.New("control character") ErrInvalidCharacter = errors.New("invalid charnacter") ErrTrailingSpace = errors.New("trailing space") ErrTrailingPeriod = errors.New("trailing period") ErrReservedDeviceName = errors.New("reserved device name") ErrNotFileOrDirectory = errors.New("not a file or directory") ErrNotDirectory = errors.New("not a directory") ErrIsAFile = errors.New("is a file") ErrIsADirectory = errors.New("is a directory") ErrCannotDetermineWorkingDirectory = errors.New("cannot determine working directory") )
var ( ErrValueIsNil = errors.New("value is nil") ErrInterfaceValueIsNil = errors.New("interface value is nil") )
var ( ErrConnectFailed = errors.New("failed to connect to database") ErrInvalidConnectString = errors.New("invalid connection string") ErrFailedToPingDatabase = errors.New("failed to ping database") ErrFailedToOpenDatabase = errors.New("failed to open database") ErrFailedToExecuteQueries = errors.New("failed to execute query(s)") )
var ( ErrFlagIsRequired = errors.New("flag is required") ErrInvalidDuplicateFlag = errors.New("invalid duplicate flag") ErrInvalidFlagName = errors.New("invalid flag name") ErrFlagValidationFailed = errors.New("flag validation failed") )
var ( ErrUnexpectedError = errors.New("unexpected error") ErrInternalError = errors.New("internal error") )
var ( ErrAccessingWorkingDir = errors.New("error accessing working dir") ErrAccessingUserConfigDir = errors.New("error accessing user config dir") ErrAccessingCLIConfigDir = errors.New("error accessing CLI config dir") ErrAccessingUserHomeDir = errors.New("error accessing user home dir") ErrAccessingUserCacheDir = errors.New("error accessing user cache dir") )
var ErrInvalidPathSeparator = errors.New("invalid path separator")
var ErrNotTildePath = errors.New("not a tilde-prefixed path")
Functions ¶
func CloseOrLog ¶
func CombineErrs ¶
CombineErrs bundles a slice of errors into a single composite error that unwraps to its members. Order is preserved and nils are skipped. Returns nil for an empty/fully-nil slice, or the sole error when there is exactly one.
func EnsureLogger ¶
func ErrValue ¶
ErrValue extracts a single metadata value by key with type safety. Returns the value and true if found and the value is of type T. Returns the zero value of T and false if not found or type mismatch.
Example:
status, ok := ErrValue[int](err, "http_status")
if ok {
fmt.Printf("Status: %d\n", status)
}
name, ok := ErrValue[string](err, "parameter_name")
func Errors ¶
Errors returns the errors stored on a doterr entry. If err is a doterr entry, returns its errors. If err is a joined error (has Unwrap() []error), scans immediate children left-to-right and returns errors from the first doterr entry found. Otherwise returns nil. The returned slice preserves insertion order and is a copy.
Note: These errors may be sentinel errors (e.g., ErrRepo), custom error types (e.g., *rfc9457.Error), or any other error type stored in the entry.
func FindErr ¶
FindErr walks an error tree (including errors.Join trees) and returns the first match for target (via errors.As).
func IndexSegments ¶ added in v0.4.0
IndexSegments returns the segment at the given index in a string split by sep. Returns empty string (cast to S) if index is out of bounds or negative.
func JoinSegments ¶ added in v0.4.0
JoinSegments returns joined slice of segments
func LogOnError ¶
func LogOnError(err error)
func MsgErr ¶ added in v0.5.0
MsgErr creates an ad-hoc error message without requiring a sentinel error. This is a convenience for rapid development - use sentinels for production code.
Accepts two forms:
- MsgErr("message") - creates error with the given message
- MsgErr(err) - wraps existing error, preserving error chain for errors.Is()
Use this when you don't want to define a sentinel immediately. Future tooling can detect MsgErr usage and suggest/generate appropriate sentinel errors.
For errors with metadata, use NewErr with a sentinel, or wrap with WithErr:
err := MsgErr("config invalid")
err = WithErr(err, "path", configPath)
func NewErr ¶
NewErr builds a standalone structured entry (no primary cause inside). Accepted parts:
- error — sentinel/tag (required: at least one, must be first)
- KV{Key,Value} — explicit key/value
- "key", value — implicit pair (value can be any type, including error)
- error — optional trailing cause (joined last via errors.Join)
Pattern: one or more sentinels (error), then zero or more key-value pairs, then optional trailing cause (error). After the first string key, all remaining args must form valid pairs, except for an optional final error. Returns nil if no meaningful parts are provided after validation. Returns a validation error joined with the partial entry if validation fails.
func ParseTimeDurationEx ¶
ParseTimeDurationEx parses a string as EITHER a Go duration format (like "3s", "10m", "1h30m") OR as an integer representing seconds.
func SliceSegments ¶ added in v0.4.0
SliceSegments returns a slice of segments from start (inclusive) to end (exclusive) in a string split by sep, similar to string[start:end] slicing. Supports -1 for end to mean "to the last segment". Returns empty slice if indices are invalid (negative start, start >= end, or out of bounds).
func SliceSegmentsScalar ¶ added in v0.4.0
SliceSegmentsScalar returns a scalar (joined) value of segments from start (inclusive) to end (exclusive) in a string split by sep, similar to string[start:end] slicing but returns a joined string. Supports -1 for end to mean "to the last segment". Returns empty string if indices are invalid. Uses a single pass through the string to find byte positions, avoiding allocations.
func SplitSegments ¶ added in v0.4.0
SplitSegments splits a string by sep separator and returns a slice of the specified segment type. It counts separators first to allocate exact capacity, optimizing for GC and heavy usage.
func UnixModeFunc ¶
UnixModeFunc provides standard Unix permissions (0755 for directories, 0644 for files)
func WithErr ¶
WithErr is a flexible enrichment helper. Typical uses:
// Enrich an existing composite error (err may be an errors.Join tree):
err = WithErr(err, "Foo", 10)
// Build an entry and join a trailing cause in one shot:
err = WithErr("endpoint", ep, ErrTemplate, cause) // 'cause' is last
Behavior:
If the FIRST arg is an error, it is treated as the base error to enrich: • If it is a doterr entry, merge KVs/sentinels into that entry. • If it is a multi-unwrap (errors.Join tree), find the RIGHTMOST doterr entry, merge into it, and rebuild preserving order. • If no doterr entry is found, a new entry will be joined in (see step 3).
After consuming the base (if present), if the LAST remaining arg is an error, it is treated as the CAUSE and joined LAST.
The remaining middle args (if any) are collected into an entry. If we enriched an existing doterr entry in step 1, that merged entry is used; otherwise, a fresh entry is created. If there is a trailing CAUSE from step 2, the result is errors.Join(entry, cause). If there is no cause, the entry is returned.
Note: For inter-function composition, prefer New() with trailing cause:
return NewErr(ErrRepo, "key", val, cause) // cause last
Types ¶
type CopyOptions ¶
type CopyOptions struct {
Overwrite bool // Overwrite existing files
DestModeFunc EntryModeFunc // Permission callback (nil = preserve source permissions)
}
CopyOptions contains options for the copy operation
type DirEntry ¶ added in v0.3.4
type DirEntry struct {
// Root is the logical root DirPath that was walked.
// It is exactly what the caller passed to Walk / WalkFS and may be
// absolute or relative.
Root DirPath
// Rel is the path of this entry relative to the fs.FS root / Root.
// It is always relative.
Rel RelPath
// Entry is the underlying fs.DirEntry. It may be nil for entries where
// fs.WalkDir reported an error before obtaining a DirEntry.
Entry fs.DirEntry
// contains filtered or unexported fields
}
DirEntry represents a filesystem entry discovered while walking a DirPath. It wraps fs.DirEntry and uses EntryPath for the entry's path relative to the walked root.
func DirPathRead ¶ added in v0.5.0
func NewDirEntryWithSkipDir ¶ added in v0.5.0
func (DirEntry) Base ¶ added in v0.3.4
Base returns the last path element of Rel as an EntryPath, similar to filepath.Base on the relative string. It does not panic and is valid for both files and directories.
func (DirEntry) DirPath ¶ added in v0.4.0
DirPath returns the entry as a directory path. It is intended for directory entries and will panic if called on a non-directory.
func (DirEntry) EntryPath ¶ added in v0.5.0
EntryPath returns the full path for a file or dir entry.
func (DirEntry) Filename ¶ added in v0.3.4
Filename returns the last path element as a Filename. It is intended for file entries and will panic if called on a non-file.
func (DirEntry) Filepath ¶ added in v0.5.0
Filepath returns the full filepath for the trny. It is intended for non-directory entries and will panic if called on a directory.
func (DirEntry) IsFile ¶ added in v0.3.4
IsFile reports whether this DirEntry represents a regular file (non-dir).
func (DirEntry) PathSegment ¶ added in v0.3.4
func (de DirEntry) PathSegment() PathSegment
PathSegment returns the last path element as a PathSegment. It is intended for directory entries and will panic if called on a non-directory.
type DirPath ¶
type DirPath string
DirPath represents an absolute or relative filesystem directory path.
It provides helper methods for working with directories while preserving type safety and semantic clarity over raw strings. A zero value is valid but does not refer to any real directory.
func DirPathJoin ¶
func DirPathJoin3 ¶
func DirPathJoin4 ¶
func DirPathJoin5 ¶
func ParseDirPath ¶
func ParseDirPaths ¶
func UserCacheDir ¶
func UserConfigDir ¶
func UserHomeDir ¶
func (DirPath) Base ¶
func (dp DirPath) Base() PathSegment
func (DirPath) EnsureExists ¶
EnsureExists verifies that the directory exists, creating it and any missing parent directories as needed.
If the path already exists as a directory, EnsureExists is a no-op. If the path exists as a file, it returns ErrPathIsFile. Any other filesystem error is returned as-is.
func (DirPath) EnsureTrailSep ¶
func (DirPath) EvalSymlinks ¶ added in v0.5.0
func (DirPath) HasDotDotPrefix ¶ added in v0.2.3
func (DirPath) IsTidlePath ¶ added in v0.5.0
func (DirPath) Normalize ¶ added in v0.5.0
Normalize expands a leading "~" to the current user's home directory (when it uses the correct OS path separator), then returns an absolute directory path.
func (DirPath) Status ¶
func (dp DirPath) Status(flags ...EntryStatusFlags) (status EntryStatus, err error)
func (DirPath) ToTilde ¶ added in v0.5.0
func (dp DirPath) ToTilde() (tdp TildeDirPath, err error)
func (DirPath) TrimPrefix ¶ added in v0.4.0
func (DirPath) TrimSuffix ¶ added in v0.4.0
func (DirPath) VolumeName ¶
func (dp DirPath) VolumeName() VolumeName
func (DirPath) Walk ¶ added in v0.3.4
Walk walks the filesystem rooted at d using d.DirFS() and yields all entries as DirEntry values together with any per-entry errors encountered.
func (DirPath) WalkDirs ¶ added in v0.3.4
WalkDirs walks using d.DirFS() and yields only entries that represent directories.
func (DirPath) WalkDirsFS ¶ added in v0.3.4
WalkDirsFS walks the provided fsys and yields only entries that represent directories.
func (DirPath) WalkFS ¶ added in v0.3.4
WalkFS walks the provided fsys (typically obtained from d.DirFS()) starting at "." and yields all entries as DirEntry values together with any per-entry errors encountered.
This implementation is non-recursive and uses fs.ReadDir internally so that it can correctly honor the iterator contract: once the caller stops iteration (yield returns false), WalkFS will not call yield again.
type EntryModeFunc ¶
EntryModeFunc is a callback that returns the desired file mode for a destination path. Return 0 to preserve the source file's permissions.
type EntryPath ¶
type EntryPath string
EntryPath can be a Filepath or a DirPath
func EntryPathJoin ¶
func EntryPathJoin3 ¶
func EntryPathJoin4 ¶
func EntryPathJoin5 ¶
func (EntryPath) Base ¶
func (ep EntryPath) Base() PathSegment
func (EntryPath) Contains ¶
Contains checks if ep contains the given substring. Accepts: string, DirPath, Filepath, EntryPath, PathSegment, or fmt.Stringer Panics on unsupported types.
func (EntryPath) EnsureTrailSep ¶
EnsureTrailSep returns ep with exactly one trailing path separator when appropriate for the platform. It does not modify an empty string.
func (EntryPath) EvalSymlinks ¶ added in v0.5.0
func (EntryPath) HasDotDotPrefix ¶ added in v0.2.3
HasDotDotPrefix reports whether p, interpreted as a relative path, starts with a ".." segment (e.g. ".." or "../foo" or "..\foo"). It does NOT treat names like "..foo" as having a dot-dot prefix.
func (EntryPath) Readlink ¶
Readlink returns the target of the symlink referred to by fp.
It returns the resolved target as a EntryPath. If fp is not a symlink, it returns an empty EntryPath and a non-nil error from os.Readlink. On most systems the returned target is relative to the directory containing fp, not an absolute path.
func (EntryPath) Status ¶
func (ep EntryPath) Status(flags ...EntryStatusFlags) (status EntryStatus, err error)
Status classifies the filesystem entry referred to by fp.
It returns IsMissingEntry when the entry does not exist (err == nil). It returns IsEntryError for all other filesystem errors (err != nil). By default it follows symlinks (like os.Stat). To inspect the entry itself, pass FlagDontFollowSymlinks.
On platforms that don't support certain kinds (e.g., sockets/devices on Windows), those statuses will never be returned.
func (EntryPath) VolumeName ¶
func (ep EntryPath) VolumeName() VolumeName
type EntryStatus ¶
type EntryStatus uint8
EntryStatus represents the classification of a filesystem entry.
It describes whether a given path refers to a file, directory, missing entry, or another type of object such as a symlink, socket, or device.
The zero value (IsInvalidEntryStatus) indicates an uninitialized or invalid status. IsEntryError denotes that an underlying filesystem error occurred; in that case, the accompanying error value from Status or LstatStatus provides additional detail.
const ( // IsInvalidEntryStatus is the zero value and indicates an uninitialized // or otherwise invalid EntryStatus. IsInvalidEntryStatus EntryStatus = iota // IsEntryError indicates a filesystem error occurred; the returned error // from Status or LstatStatus will contain the details. IsEntryError // IsMissingEntry indicates the entry does not exist (fs.ErrNotExist). IsMissingEntry // IsFileEntry indicates a regular file. IsFileEntry // IsDirEntry indicates a directory. IsDirEntry IsSymlinkEntry IsSocketEntry IsPipeEntry IsDeviceEntry // IsUnclassifiedEntryStatus indicates some other kind of filesystem entry such as // a symlink, socket, device, or named pipe. IsUnclassifiedEntryStatus )
func (EntryStatus) String ¶
func (s EntryStatus) String() string
String returns a human-readable representation of the EntryStatus.
It is primarily intended for diagnostic output and logging; program logic should use the EntryStatus constants directly.
type EntryStatusFlags ¶
type EntryStatusFlags uint32
EntryStatusFlags controls optional classification behavior. The zero value is safe and means "follow symlinks" (os.Stat).
const ( // DontFollowSymlinks causes Status to inspect the entry itself // (os.Lstat) instead of following symlinks. DontFollowSymlinks EntryStatusFlags = 1 << iota )
type ErrKV ¶ added in v0.5.0
ErrKV represents a key/value metadata pair. Keys are preserved in insertion order, and values may be of any type.
func AnyKV ¶ added in v0.5.0
AnyKV creates a KV with any value type. Use this for custom types or when the specific type constructor doesn't exist.
func AppendKV ¶ added in v0.5.0
AppendKV appends key-value pairs to a slice of KV values. It accepts variadic arguments in three forms:
- Individual KV values: AppendKV(kvs, StringKV("foo", "bar"))
- String key-value pairs: AppendKV(kvs, "foo", "bar")
- Lazy ErrKV functions: AppendKV(kvs, func()ErrKV{ return StringKV("expensive", compute()) })
This function is useful for accumulating metadata throughout a function before creating an error:
var kvs []ErrKV
kvs = AppendKV(kvs, "user_id", userID)
if complexCondition {
kvs = AppendKV(kvs, "reason", "complex")
}
return NewErr(ErrFailed, kvs, cause)
String key-value pairs must come in even counts (odd counts panic in debug mode). Lazy functions (func()ErrKV) are wrapped and not evaluated until error creation.
func ErrMeta ¶
ErrMeta returns the key/value pairs stored on all doterr entries in the error tree. If err is a doterr entry, returns its metadata. If err is a joined error (has Unwrap() []error), scans all children recursively and collects metadata from all doterr entries found, preserving order. Otherwise returns nil. The returned slice preserves insertion order across all entries.
func ErrorKV ¶ added in v0.5.0
ErrorKV creates a KV with an error value. Use this when you want to include an error as metadata (not as a cause).
type Filename ¶
type Filename string
Filename with name and extension, if exists, but no path component
type Filepath ¶
type Filepath string
Filepath is an absolute or relativate filepath with filename including extension if applicable
func FilepathJoin ¶
func FilepathJoin3 ¶
func FilepathJoin4 ¶
func FilepathJoin5 ¶
func ParseFilepath ¶
func (Filepath) CopyTo ¶
func (fp Filepath) CopyTo(dest Filepath, opts *CopyOptions) (err error)
CopyTo copies the file to the destination filepath with optional permission control
func (Filepath) CopyToDir ¶
func (fp Filepath) CopyToDir(dest DirPath, opts *CopyOptions) (err error)
CopyToDir copies the file to the destination directory path with optional permission control
func (Filepath) EvalSymlinks ¶ added in v0.5.0
func (Filepath) HasDotDotPrefix ¶ added in v0.2.3
func (Filepath) Readlink ¶
Readlink returns the target of the symlink referred to by fp.
It returns the resolved target as a Filepath. If fp is not a symlink, it returns an empty Filepath and a non-nil error from os.Readlink. On most systems the returned target is relative to the directory containing fp, not an absolute path.
func (Filepath) Status ¶
func (fp Filepath) Status(flags ...EntryStatusFlags) (status EntryStatus, err error)
Status classifies the filesystem entry referred to by fp.
It returns IsMissingEntry when the entry does not exist (err == nil). It returns IsEntryError for all other filesystem errors (err != nil). By default it follows symlinks (like os.Stat). To inspect the entry itself, pass FlagDontFollowSymlinks.
On platforms that don't support certain kinds (e.g., sockets/devices on Windows), those statuses will never be returned.
func (Filepath) StringLike ¶
func (Filepath) StringLike()
type FilepathGetter ¶ added in v0.3.0
type FilepathGetter interface {
Filepath() Filepath
}
type Identifier ¶
type Identifier string
func ParseIdentifier ¶ added in v0.4.0
func ParseIdentifier(s string) (id Identifier, err error)
type InternetDomain ¶ added in v0.4.0
type InternetDomain string
InternetDomain is used for internet domains like google.com or www.example.com.
type PathSegment ¶
type PathSegment string
func (PathSegment) Contains ¶
func (ps PathSegment) Contains(part any) bool
func (PathSegment) Exists ¶ added in v0.3.3
func (ps PathSegment) Exists() (exists bool, err error)
func (PathSegment) HasDotDotPrefix ¶ added in v0.2.3
func (ps PathSegment) HasDotDotPrefix() bool
func (PathSegment) MkdirAll ¶ added in v0.3.3
func (ps PathSegment) MkdirAll(mode os.FileMode) error
func (PathSegment) Status ¶ added in v0.3.3
func (ps PathSegment) Status(flags ...EntryStatusFlags) (status EntryStatus, err error)
Status classifies the filesystem entry referred to by fp.
It returns IsMissingEntry when the entry does not exist (err == nil). It returns IsEntryError for all other filesystem errors (err != nil). By default it follows symlinks (like os.Stat). To inspect the entry itself, pass FlagDontFollowSymlinks.
On platforms that don't support certain kinds (e.g., sockets/devices on Windows), those statuses will never be returned.
func (PathSegment) TrimPrefix ¶ added in v0.4.0
func (ps PathSegment) TrimPrefix(prefix DirPath) PathSegment
func (PathSegment) TrimSuffix ¶ added in v0.4.0
func (ps PathSegment) TrimSuffix(TrimSuffix string) PathSegment
type PathSegments ¶
type PathSegments string
PathSegments is one or more path segments for a filesystem path
func ParentPath ¶ added in v0.5.0
func ParentPath() PathSegments
func PathSegmentsJoin ¶ added in v0.4.0
func PathSegmentsJoin[T1, T2 ~string](a T1, b T2) PathSegments
func PathSegmentsJoin3 ¶ added in v0.4.0
func PathSegmentsJoin3[T1, T2, T3 ~string](a T1, b T2, c T3) PathSegments
func PathSegmentsJoin4 ¶ added in v0.4.0
func PathSegmentsJoin4[T1, T2, T3, T4 ~string](a T1, b T2, c T3, d T4) PathSegments
func PathSegmentsJoin5 ¶ added in v0.4.0
func PathSegmentsJoin5[T1, T2, T3, T4, T5 ~string](a T1, b T2, c T3, d T4, e T5) PathSegments
func (PathSegments) Contains ¶ added in v0.5.0
func (pss PathSegments) Contains(part any) bool
func (PathSegments) Escapes ¶ added in v0.5.0
func (pss PathSegments) Escapes() (escapes bool)
func (PathSegments) FromSlash ¶ added in v0.5.0
func (pss PathSegments) FromSlash() PathSegments
func (PathSegments) HasPrefix ¶ added in v0.5.0
func (pss PathSegments) HasPrefix(prefix PathSegments) bool
func (PathSegments) HasSuffix ¶ added in v0.5.0
func (pss PathSegments) HasSuffix(suffix string) bool
func (PathSegments) LastIndex ¶ added in v0.4.0
func (pss PathSegments) LastIndex(sep string) int
func (PathSegments) Normalize ¶ added in v0.5.0
func (pss PathSegments) Normalize() PathSegments
Normalize returns a consistent format given different inputs when represent the same path
func (PathSegments) Segment ¶ added in v0.4.0
func (pss PathSegments) Segment(index int) PathSegment
Segment returns the segment at the given index in the path. Returns empty PathSegment if index is out of bounds or negative.
func (PathSegments) Segments ¶
func (pss PathSegments) Segments() []PathSegment
Segments returns all segments of the path, same as Split.
func (PathSegments) Slice ¶ added in v0.4.0
func (pss PathSegments) Slice(start, end int) []PathSegment
Slice returns segments from start (inclusive) to end (exclusive), similar to string[start:end] slicing.
func (PathSegments) SliceScalar ¶ added in v0.4.0
func (pss PathSegments) SliceScalar(start, end int) PathSegments
SliceScalar returns a scalar (joined) value of segments from start (inclusive) to end (exclusive), similar to string[start:end] slicing but returns a joined string using the OS separator. Supports -1 for end to mean "to the last segment".
func (PathSegments) Split ¶ added in v0.2.3
func (pss PathSegments) Split() []PathSegment
Split returns all segments of the path separated by the OS separator as a slice of PathSegment.
func (PathSegments) ToLower ¶ added in v0.5.0
func (pss PathSegments) ToLower() PathSegments
func (PathSegments) ToSlash ¶ added in v0.5.0
func (pss PathSegments) ToSlash() PathSegments
func (PathSegments) ToUpper ¶ added in v0.5.0
func (pss PathSegments) ToUpper() PathSegments
func (PathSegments) TrimPrefix ¶ added in v0.5.0
func (pss PathSegments) TrimPrefix(prefix PathSegments) PathSegments
func (PathSegments) TrimSpace ¶ added in v0.5.0
func (pss PathSegments) TrimSpace() PathSegments
func (PathSegments) TrimSuffix ¶ added in v0.5.0
func (pss PathSegments) TrimSuffix(TrimSuffix string) PathSegments
func (PathSegments) UpperFirst ¶
func (pss PathSegments) UpperFirst() PathSegments
type RelDirPath ¶ added in v0.5.0
type RelDirPath = PathSegments
type RelFilepath ¶
type RelFilepath string
RelFilepath is an relativate filepath with filename including extension if applicable
func RelFilepathJoin ¶
func RelFilepathJoin[T1, T2 ~string](a T1, b T2) RelFilepath
func RelFilepathJoin3 ¶
func RelFilepathJoin3[T1, T2, T3 ~string](a T1, b T2, c T3) RelFilepath
func RelFilepathJoin4 ¶
func RelFilepathJoin4[T1, T2, T3, T4 ~string](a T1, b T2, c T3, d T4) RelFilepath
func RelFilepathJoin5 ¶
func RelFilepathJoin5[T1, T2, T3, T4, T5 ~string](a T1, b T2, c T3, d T4, e T5) RelFilepath
func (RelFilepath) Base ¶
func (fp RelFilepath) Base() Filename
func (RelFilepath) Dir ¶
func (fp RelFilepath) Dir() DirPath
func (RelFilepath) Exists ¶ added in v0.3.2
func (fp RelFilepath) Exists() (exists bool, err error)
func (RelFilepath) Rel ¶ added in v0.3.2
func (fp RelFilepath) Rel(baseDir DirPath) (RelFilepath, error)
func (RelFilepath) Status ¶ added in v0.3.2
func (fp RelFilepath) Status(flags ...EntryStatusFlags) (status EntryStatus, err error)
Status classifies the filesystem entry referred to by fp.
It returns IsMissingEntry when the entry does not exist (err == nil). It returns IsEntryError for all other filesystem errors (err != nil). By default it follows symlinks (like os.Stat). To inspect the entry itself, pass FlagDontFollowSymlinks.
On platforms that don't support certain kinds (e.g., sockets/devices on Windows), those statuses will never be returned.
func (RelFilepath) ValidPath ¶
func (fp RelFilepath) ValidPath() bool
type RelPath ¶ added in v0.5.0
type RelPath string
RelPath can be a RelFilepath or a PathSegments
func (RelPath) Base ¶ added in v0.5.0
func (rp RelPath) Base() PathSegment
func (RelPath) Contains ¶ added in v0.5.0
Contains checks if ep contains the given substring. Accepts: string, DirPath, Filepath, RelPath, PathSegment, or fmt.Stringer Panics on unsupported types.
func (RelPath) Readlink ¶ added in v0.5.0
Readlink returns the target of the symlink referred to by fp.
It returns the resolved target as a RelPath. If fp is not a symlink, it returns an empty RelPath and a non-nil error from os.Readlink. On most systems the returned target is relative to the directory containing fp, not an absolute path.
func (RelPath) Status ¶ added in v0.5.0
func (rp RelPath) Status(flags ...EntryStatusFlags) (status EntryStatus, err error)
Status classifies the filesystem entry referred to by fp.
It returns IsMissingEntry when the entry does not exist (err == nil). It returns IsEntryError for all other filesystem errors (err != nil). By default it follows symlinks (like os.Stat). To inspect the entry itself, pass FlagDontFollowSymlinks.
On platforms that don't support certain kinds (e.g., sockets/devices on Windows), those statuses will never be returned.
func (RelPath) VolumeName ¶ added in v0.5.0
func (rp RelPath) VolumeName() VolumeName
type TildeDirPath ¶ added in v0.5.0
type TildeDirPath string
func ParseTildeDirPath ¶ added in v0.5.0
func ParseTildeDirPath(s string) (tdp TildeDirPath, err error)
func TildeDirPathJoin ¶ added in v0.5.0
func TildeDirPathJoin[T1, T2 ~string](a T1, b T2) TildeDirPath
func (TildeDirPath) Expand ¶ added in v0.5.0
func (tdp TildeDirPath) Expand() (dp DirPath, err error)
type TimeFormat ¶ added in v0.4.0
type TimeFormat string
TimeFormat controls how timestamps are rendered: e.g. "2006-01-02".
type URL ¶
type URL string
URL is a string that contains a syntactically valid Uniform Resource Locator A valid URL would be parsed without error by net/url.URL.Parse().
type URLSegment ¶ added in v0.4.0
type URLSegment string
func ParseURLSegment ¶ added in v0.5.0
func ParseURLSegment(s string) (uss URLSegment, err error)
func (URLSegment) Contains ¶ added in v0.4.0
func (ps URLSegment) Contains(part any) bool
func (URLSegment) HasDotDotPrefix ¶ added in v0.4.0
func (ps URLSegment) HasDotDotPrefix() bool
type URLSegments ¶ added in v0.4.0
type URLSegments string
URLSegments is one or more path segments for a filepath, dir path, or URL
func ParseURLSegments ¶ added in v0.4.0
func ParseURLSegments(s string) (uss URLSegments, err error)
func URLSegmentsJoin ¶ added in v0.4.0
func URLSegmentsJoin[T1, T2 ~string](a T1, b T2) URLSegments
func URLSegmentsJoin3 ¶ added in v0.4.0
func URLSegmentsJoin3[T1, T2, T3 ~string](a T1, b T2, c T3) URLSegments
func URLSegmentsJoin4 ¶ added in v0.4.0
func URLSegmentsJoin4[T1, T2, T3, T4 ~string](a T1, b T2, c T3, d T4) URLSegments
func URLSegmentsJoin5 ¶ added in v0.4.0
func URLSegmentsJoin5[T1, T2, T3, T4, T5 ~string](a T1, b T2, c T3, d T4, e T5) URLSegments
func (URLSegments) Base ¶ added in v0.4.0
func (uss URLSegments) Base() URLSegment
func (URLSegments) LastIndex ¶ added in v0.4.0
func (uss URLSegments) LastIndex(sep string) int
func (URLSegments) Segment ¶ added in v0.4.0
func (uss URLSegments) Segment(index int) URLSegment
func (URLSegments) Segments ¶ added in v0.4.0
func (uss URLSegments) Segments() []URLSegment
func (URLSegments) Slice ¶ added in v0.4.0
func (uss URLSegments) Slice(start, end int) []URLSegment
func (URLSegments) SliceScalar ¶ added in v0.4.0
func (uss URLSegments) SliceScalar(start, end int, sep string) URLSegment
func (URLSegments) Split ¶ added in v0.4.0
func (uss URLSegments) Split() []URLSegment
type Version ¶
type Version string
Version is a string uses for a software version. It is mainly without constraint as people have defined versions in many different ways over time.
type VolumeName ¶
type VolumeName string
VolumeName returns the name of the mounted volume on Windows. It might be "C:" or "\\server\share". On other platforms it is always an empty string.
Source Files
¶
- can_write_path.go
- chtimes.go
- config.go
- copy_options.go
- dir_entry.go
- dir_path.go
- doterr.go
- entry_path.go
- entry_status.go
- errors.go
- filename.go
- filepath.go
- identifier.go
- io_fs.go
- join.go
- logger.go
- os.go
- path_segment.go
- path_segments.go
- path_segments_ext.go
- rel_filepath.go
- rel_path.go
- segments.go
- stat.go
- tilde_dir_path.go
- time.go
- types.go
- url.go
- url_segment.go
- url_segments.go
- util.go
- walk_dir.go