Documentation
¶
Overview ¶
Package config locates RemoHop's on-disk state.
Index ¶
- func All() (map[string]string, error)
- func AllIn(dir string) (map[string]string, error)
- func Bool(value string, def bool) bool
- func Dir() (string, error)
- func Get(key string) (string, error)
- func IsPrivate(path string) (bool, error)
- func Lock(path string) (unlock func(), err error)
- func MakePrivate(dir string) error
- func ReadFile(path string) ([]byte, error)
- func RegisterSetting(s Setting)
- func Rename(oldpath, newpath string) error
- func Set(key, value string) error
- func SubDir(name string) (string, error)
- func ValidateOnOff(v string) error
- func WriteFileAtomic(path string, data []byte, perm os.FileMode) error
- type Setting
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllIn ¶
AllIn returns every value stored in the config file of a specific config directory. Long-running processes that were started on a directory read their live settings through it.
func Bool ¶
Bool interprets a stored on/off value; anything else, including an unset key, yields def.
func Dir ¶
Dir is where configuration and credentials live: $REMOHOP_CONFIG_DIR, or "remohop" under the user's config directory (~/.config/remohop on Linux). The directory is created with mode 0700 because it holds key material.
func Lock ¶
Lock takes a cross-process advisory lock guarding path, for the read-modify-write cycles on small state files that several remohop processes share (saved peers, pairing tokens). The lock is an operating-system file lock (flock, LockFileEx) on path+".lock": it is released by the system if the holder dies, so there is nothing stale to clean up, and the lock file itself is never deleted, because removing a file that another process has open or is about to open is exactly what does not work on Windows. Call the returned function to release.
func MakePrivate ¶
MakePrivate makes sure dir is a safe place for this user's key material. Files in it are created 0600 by every writer in this module, but that does not stop someone who can write to the directory from replacing them (a rename needs only write access to the directory), so:
- a directory of this user's that others may write to is tightened to the owner only (not a sticky directory such as /tmp, which is shared by design);
- a directory that belongs to another user (other than root) is refused;
- one that everybody may write to and that cannot be fixed is refused.
Group write is accepted when it cannot be removed (the directory is root's: a volume shared with a container's group, say). A directory that others can only read is left as it is.
func ReadFile ¶
ReadFile is os.ReadFile made tolerant of the transient sharing violations described at replaceFile: on Windows a read that races a WriteFileAtomic rename over the same file can fail for a moment. A file that does not exist is reported at once.
func RegisterSetting ¶
func RegisterSetting(s Setting)
RegisterSetting declares a config key. It panics on a duplicate so two packages cannot silently share one.
func Rename ¶
Rename is os.Rename made tolerant of the transient sharing violations described at replaceFile; use it to rotate or replace files that other remohop processes may be reading.
func Set ¶
Set stores value under key; an empty value removes the key. The key must have been declared and the value must pass its validation.
func SubDir ¶
SubDir returns (and creates, mode 0700) a named directory under Dir, for feature state such as clipboard history or spawn logs.
func ValidateOnOff ¶
ValidateOnOff is a Setting.Validate for on/off keys.
func WriteFileAtomic ¶
WriteFileAtomic replaces path with data so that a reader (or a crash) sees either the old or the new content, never a mix: the bytes go to a temporary file in the same directory, are synced, and are renamed over the target.
Types ¶
type Setting ¶
type Setting struct {
Key string
Help string
// Validate rejects malformed values; nil accepts anything.
Validate func(value string) error
// Secret values are masked when all settings are listed.
Secret bool
// Default is shown in listings for a key that is not set.
Default string
}
Setting describes one key of the user's config file (config.json in Dir), edited with `remohop config set`. Packages declare the keys they read with RegisterSetting so the command can validate and document them.
func LookupSetting ¶
LookupSetting finds a declared key.