config

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 14 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 reads and writes ytrack's configuration directory:

config.yml  general preferences
hosts.yml   per-host metadata and the default host (never secrets)

The directory is $YTRACK_CONFIG_DIR, else $XDG_CONFIG_HOME/ytrack, else %AppData%/ytrack on Windows, else ~/.config/ytrack.

Machine state that is not configuration (the update check) lives in StateDir.

Index

Constants

View Source
const (
	StorageKeyring = "keyring"
	StorageFile    = "file"
)

Storage values record where a host's token lives.

View Source
const ProjectCacheTTL = 7 * 24 * time.Hour

ProjectCacheTTL is how long a cached answer to "does host H have project P" is trusted.

Variables

This section is empty.

Functions

func CacheDir added in v0.5.2

func CacheDir() (string, error)

CacheDir returns the directory for data ytrack can rebuild: $YTRACK_CACHE_DIR, else $XDG_CACHE_HOME/ytrack, else the OS user cache directory plus ytrack (~/.cache/ytrack on Linux).

func Dir

func Dir() (string, error)

Dir returns the configuration directory.

func SetPathOS added in v0.5.0

func SetPathOS(goos string) (restore func())

SetPathOS makes path globs compare as on goos (a runtime.GOOS value) until restore is called. It lets tests cover every OS from one machine.

func StateDir added in v0.2.0

func StateDir() (string, error)

StateDir returns the directory for state ytrack keeps between runs: $XDG_STATE_HOME/ytrack, else %LocalAppData%/ytrack on Windows, else ~/.local/state/ytrack.

func ValidatePathGlob added in v0.4.0

func ValidatePathGlob(glob string) error

ValidatePathGlob reports why glob cannot be a host path. A path glob is absolute or starts with ~/, and its only wildcards are * (within one folder name) and ** (any number of folders): /home/me/work/**.

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte) error

WriteFileAtomic writes data to path with mode 0600, creating the parent directory with mode 0700, via a temp file and rename.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config is the loaded configuration.

func Load

func Load() (*Config, error)

Load reads the configuration from Dir. Missing files mean empty config.

func LoadFrom

func LoadFrom(dir string) (*Config, error)

LoadFrom reads the configuration from dir.

func (*Config) AddHostPath added in v0.4.0

func (c *Config) AddHostPath(key, glob string) (bool, error)

AddHostPath adds glob to the paths of host key, which must be known. It reports whether the glob was new (see FindHostPath).

func (*Config) Browser

func (c *Config) Browser() string

Browser returns the configured browser launcher, if any.

func (*Config) CheckUpdate added in v0.2.0

func (c *Config) CheckUpdate() bool

CheckUpdate reports whether the new-release notice is on (`check_update` in config.yml, default true).

func (*Config) DefaultHost

func (c *Config) DefaultHost() string

DefaultHost returns the key of the default host, or "".

func (*Config) Dir

func (c *Config) Dir() string

Dir returns the directory this config was loaded from.

func (*Config) FindHostPath added in v0.5.0

func (c *Config) FindHostPath(key, glob string) (string, bool)

FindHostPath returns the stored path of host key that names the same path as glob (see samePath).

func (*Config) Host

func (c *Config) Host(key string) *HostEntry

Host returns the entry for key, or nil.

func (*Config) HostForPath added in v0.4.0

func (c *Config) HostForPath(dirs ...string) (PathMatch, bool, error)

HostForPath returns the host whose path glob matches one of dirs. The most specific glob wins: the one with the longest literal text before its first wildcard. A tie goes to the host key that sorts first.

On macOS and Windows globs match regardless of case. When the most specific matching globs include two of different hosts that differ only by case, it is an error naming both: the user meant one folder, so neither host is picked. A narrower glob that also matches still wins, and the same glob on two hosts keeps the tie rule.

func (*Config) HostKeys

func (c *Config) HostKeys() []string

HostKeys returns the known host keys, sorted.

func (*Config) HostPaths added in v0.4.0

func (c *Config) HostPaths(key string) []string

HostPaths returns the path globs of host key.

func (*Config) RemoveHost

func (c *Config) RemoveHost(key string)

RemoveHost deletes a host entry. If it was the default, the first remaining host (sorted) becomes the default.

func (*Config) RemoveHostPath added in v0.4.0

func (c *Config) RemoveHostPath(key, glob string) bool

RemoveHostPath removes glob from the paths of host key and reports whether it was there (see FindHostPath).

func (*Config) Save

func (c *Config) Save() error

Save writes hosts.yml and config.yml with owner-only permissions.

func (*Config) SetDefaultHost

func (c *Config) SetDefaultHost(key string) error

SetDefaultHost makes key the default host. The host must be known.

func (*Config) SetHost

func (c *Config) SetHost(key string, entry HostEntry)

SetHost adds or replaces a host entry, keeping the folder paths of the entry it replaces when entry has none. The first host becomes the default.

func (*Config) Timezone

func (c *Config) Timezone() string

Timezone returns the configured work timezone, or "".

type HostEntry

type HostEntry struct {
	URL     string `yaml:"url"`
	User    string `yaml:"user,omitempty"`
	Auth    string `yaml:"auth,omitempty"`
	Storage string `yaml:"storage,omitempty"`
	// Paths are folder globs (/abs/dir/**, ~/dir/**) whose commands talk to
	// this host when no --host, issue URL or $YTRACK_HOST picks one.
	Paths []string `yaml:"paths,omitempty"`
}

HostEntry is the non-secret metadata kept for a logged-in host.

type PathMatch added in v0.4.0

type PathMatch struct {
	Host string // host key
	Glob string // the matching glob, as stored
}

PathMatch is the host a folder resolves to through the paths in hosts.yml.

type ProjectCache added in v0.5.2

type ProjectCache struct {
	Dir string
	Now func() time.Time
}

ProjectCache remembers, per host service URL and project short name, whether the host has that project, for ProjectCacheTTL. It is a hint: a missing, stale or unreadable file means "unknown".

func (ProjectCache) Lookup added in v0.5.2

func (c ProjectCache) Lookup(hostURL, project string) (has, known bool)

Lookup returns whether the host at hostURL has project and whether the cache knows.

func (ProjectCache) Store added in v0.5.2

func (c ProjectCache) Store(hostURL, project string, has bool)

Store records whether the host at hostURL has project. Errors are ignored: the cache is only a hint.

Jump to

Keyboard shortcuts

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