config

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config locates RemoHop's on-disk state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All() (map[string]string, error)

All returns every value stored in the config file.

func AllIn

func AllIn(dir string) (map[string]string, error)

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

func Bool(value string, def bool) bool

Bool interprets a stored on/off value; anything else, including an unset key, yields def.

func Dir

func Dir() (string, error)

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 Get

func Get(key string) (string, error)

Get returns the stored value for key, or "" when it is not set.

func IsPrivate

func IsPrivate(path string) (bool, error)

IsPrivate reports whether path is inaccessible to group and others.

func Lock

func Lock(path string) (unlock func(), err error)

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

func MakePrivate(dir string) error

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

func ReadFile(path string) ([]byte, error)

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

func Rename(oldpath, newpath string) error

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

func Set(key, value string) error

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

func SubDir(name string) (string, error)

SubDir returns (and creates, mode 0700) a named directory under Dir, for feature state such as clipboard history or spawn logs.

func ValidateOnOff

func ValidateOnOff(v string) error

ValidateOnOff is a Setting.Validate for on/off keys.

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, perm os.FileMode) error

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

func LookupSetting(key string) (Setting, bool)

LookupSetting finds a declared key.

func Settings

func Settings() []Setting

Settings lists the declared keys, sorted.

Jump to

Keyboard shortcuts

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