go.bigb.es/cacher @ v0.1.2 — 9dc739e5 2 months ago
import "go.bigb.es/cacher/internal/config"
ApplyEnv overlays CACHER_<UPPER> environment variables onto cfg. Unset/empty variables are ignored (do not zero out file values).
func DefaultPath() (string, error)
DefaultPath returns ~/.config/cacher/config.toml on every platform. We deliberately do not use os.UserConfigDir (which returns ~/Library/Application Support on macOS) because cacher is a CI tool that needs the same path on a developer's mac and on a Linux build runner.
func ExpandPath(p string) string
ExpandPath expands a leading ~ in a path against $HOME.
type Config struct { Endpoint string `toml:"endpoint"` Region string `toml:"region"` Bucket string `toml:"bucket"` Prefix string `toml:"prefix"` ArchSuffix bool `toml:"arch_suffix"` // KeyFile / SecretFile point at files that contain the raw credential // material (whitespace is stripped on load). Used in CI where secrets // are mounted as files. Env vars CACHER_S3_KEY_ID / CACHER_S3_SECRET // take priority for local-dev runs. KeyFile string `toml:"key_file"` SecretFile string `toml:"secret_file"` }
Config is the persisted cacher configuration. The TOML file under ~/.config/cacher/config.toml holds the same fields. Every field is overridable via CACHER_<UPPER> environment variables.
Defaults returns built-in defaults. They are overlaid by file → env → flags.
Load reads the config file at path (empty path = DefaultPath). A missing file is not an error — it returns Defaults(). Env vars and flag overlays must be applied by the caller afterwards.
func (c Config) Credentials() (keyID, secret string, err error)
Credentials resolves the S3 access key + secret with precedence:
Whitespace (including trailing newlines) is trimmed from file contents.
Package config loads cacher configuration with precedence: flag > env (CACHER_*) > config file (~/.config/cacher/config.toml) > defaults.