Documentation ¶
Overview ¶
Provides shortcuts to os.UserHomeDir, os.UserConfigDir & os.UserCacheDir, the ability to Resolve a path, and a way to store os.Stat info as FileInfo via Open.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cache ¶
func Cache() string
Returns os.UserCacheDir, but the value is cached locally to avoid unnecessary repeat calls.
func Config ¶
func Config() string
Returns os.UserConfigDir, but the value is cached locally to avoid unnecessary repeat calls.
func Home ¶
func Home() string
Returns os.UserHomeDir, but the value is cached locally to avoid unnecessary repeat calls.
Types ¶
type FileInfo ¶
type FileInfo struct { Path string `json:"path"` IsRegular bool `json:"is_regular"` IsDir bool `json:"is_dir"` Name string `json:"filename"` Size int64 `json:"size"` Modified time.Time `json:"modified"` }
Stores information on a file.
func Open ¶
Calls os.Open and then os.File.Stat to populate FileInfo.
func (*FileInfo) Equals ¶
Determines if this *FileInfo is the same as other by comparing name, size & modified time.Time.
type FileInfoError ¶
type FileInfoError struct {
// contains filtered or unexported fields
}
Error returned by Open, contains errors returned by os.Open & os.Stat so you may utilise errors.Is like so...
fi, err := paths.Open(path) if errors.Is(err, os.PathError) { ... }
func (*FileInfoError) Error ¶
func (e *FileInfoError) Error() string
func (*FileInfoError) Unwrap ¶
func (e *FileInfoError) Unwrap() error
type Path ¶
type Path string
A Path is just a string that can be operated on.
All operations are platform agnostic.
type PathResolver ¶
For more complex operations, this struct is provided to facilitate options such as considering `$HOME` when resolving.
func NewPathResolver ¶
func NewPathResolver(path string, options ...ResolverOption) *PathResolver
Create a new *PathResolver.
r := paths.NewPathResolver(path, paths.ResolveToHome()) path, err := r.Resolve()
type ResolverOption ¶
type ResolverOption func(*PathResolver)
ResolverOption is a function that accepts a *PathResolver and applies some configuration.
func ResolveToHome ¶
func ResolveToHome() ResolverOption
Pass this to NewPathResolver to instruct PathResolver to consider `$HOME` when resolving a path.