You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Every choice appdir makes has an option, and every option has the standard's default, so appdir.New("lore") with no options is already a tool on the standard. This page lists every Option and every KindOption, grouped by what they change, with the default as the code sets it and the guide that explains it in depth.
Options are applied in the order given, after the defaults. A setter given twice keeps the last value. WithKind, WithoutKind, WithGitCommit, WithGitIgnore and WithLegacyHome add to a list, and the kind edits are applied in order. WithProfiles replaces the list. New then validates the whole set and returns an error wrapping ErrInvalidOption for a bad one (see Errors and exit codes).
All defaults below are set in one place, defaultConfig, with the numbers in the defaults block.
The home folder name: global ~/<name>, project <name>/. Must be one plain path segment: not empty, not . or .., no /, \ or NUL; else ErrInvalidOption from New.
The app name itself is the first argument of New and must match ^[a-z0-9][a-z0-9._-]*$.
Lookup and mode
Option
Default
What it changes
Guide
WithMode(m Mode)
ModeProject
The default scope of data kinds: ModeProject puts db, backups, run, shared in the project home (and logs in the project home, else the global one); ModeGlobal puts them in the global home. Anything else is ErrInvalidOption.
Adds a kind or changes an existing one in place. A new kind starts as Folder(name), Ignore(), the mode's data scope. The name must match ^[a-z][a-z0-9-]*$.
Names an old global home folder (LegacyHome{Dir: ".pm"}) that MoveLegacy moves from. Dir must be one path segment. DaemonLocks defaults to ["run/daemon.lock"]. Repeatable; the first that exists is used.
typeLegacyHomestruct {
Dirstring// folder name under the user's home, e.g. ".pm"DaemonLocks []string// lock files inside it to probe; default ["run/daemon.lock"]
}
typeLegacyVerifyfunc(src, dststring) error
Config reader
Option
Default
What it changes
Guide
WithConfigReader(fn ConfigReader)
the internal JSONC reader
How home.jsonc and the home: / db: pointer keys are read. A missing file must return an error wrapping fs.ErrNotExist. nil is ErrInvalidOption.
The default names by RunFile: RunLock is lock, RunDaemonLock is daemon.lock, RunPID is <app>.pid, RunDiscovery is discovery.json, RunSocket is <app>.sock, RunSocketFile is socket.
Permissions and fallbacks
Option
Default
What it changes
Guide
WithPerm(dir, file fs.FileMode)
0700, 0600
The modes of folders and files appdir creates. On Windows the mode bits are ignored and appdir sets an owner-only ACL instead.
Lets disposable kinds (such as cache) fall back to <tmp>/<app>-<uid>/ when there is no home folder, or when Ensure cannot create them because the home is read-only.
New builds the option set once and never changes it, and every *Dirs method only reads it. Methods that return slices (Paths, Kinds, Warnings, ConfigFiles) return a fresh copy, so a caller can change the result without affecting other callers. One *Dirs can be shared by every goroutine of a tool.
appdir keeps no package-level mutable state: the only package-level variables are the sentinel errors, which are never reassigned, and the standard layout is built fresh on each call. Two New calls with different options in one process do not affect each other. To see another profile's paths, call ForProfile, which resolves a new *Dirs and leaves the first one alone.