config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package config handles profile + batch-state persistence under the per-user configuration directory.

Index

Constants

View Source
const (
	EnvConfig = "READUR_CONFIG"
)

Env variables honored when resolving paths.

View Source
const EnvProfile = "READUR_PROFILE"

EnvProfile names the profile to use, overriding the file-level default_profile. Precedence: --profile flag > READUR_PROFILE env var > file default_profile.

Variables

This section is empty.

Functions

func EnsureDir

func EnsureDir(dir string) error

EnsureDir creates dir with 0700 permissions if it does not exist. On Windows the perm bits are advisory; the per-user AppData directory's default ACL already restricts access.

Types

type Paths

type Paths struct {
	// ConfigDir is the directory holding config.toml and the state/
	// subdirectory. It is created on demand.
	ConfigDir string
	// ConfigFile is the TOML profile file path.
	ConfigFile string
	// StateDir holds per-batch resume state files.
	StateDir string
}

Paths resolves the filesystem locations used by the CLI.

func Resolve

func Resolve(override string) (Paths, error)

Resolve returns the Paths to use, honoring an explicit override (typically --config or READUR_CONFIG) when non-empty. An override points directly at the config.toml file; its directory is taken as ConfigDir.

When no override is supplied the function uses xdg.ConfigHome (which resolves correctly on Linux, macOS, and Windows).

type Profile

type Profile struct {
	Name               string    `toml:"-"`
	ServerURL          string    `toml:"server_url"`
	Username           string    `toml:"username"`
	Token              string    `toml:"token"`
	TokenExpiry        time.Time `toml:"token_expiry,omitempty"`
	ObtainedAt         time.Time `toml:"obtained_at"`
	InsecureSkipVerify bool      `toml:"insecure_skip_verify,omitempty"`
	Password           string    `toml:"password,omitempty"`
}

Profile is a named, per-user record of how to reach one Readur server. Field names match the TOML keys exactly.

Password is optional: it is present only when the user opted in via `readur login --save-password`. When non-empty, the HTTP client uses it to silently refresh an expired or revoked token (see research.md §11). The field is treated as a secret exactly like Token — redacted in every subcommand's output and protected by the 0600 save path.

func ResolveProfile

func ResolveProfile(profiles map[string]*Profile, defaultProfile, flagProfile string) (*Profile, error)

ResolveProfile selects the active profile from a loaded map following the precedence flag > env > defaultProfile. Returns CodeConfig if no profile can be resolved.

func (*Profile) Validate

func (p *Profile) Validate() error

Validate checks required fields. Called before save.

type Store

type Store struct {
	Paths Paths
}

Store is the read/write handle for the config file. It is cheap to construct and safe to use from a single goroutine.

func NewStore

func NewStore(p Paths) *Store

NewStore builds a Store from a resolved Paths.

func (*Store) Load

func (s *Store) Load() (map[string]*Profile, string, error)

Load reads config.toml and returns all profiles along with the file-level default_profile name (possibly empty if none is set). If the file does not exist, Load returns an empty result with no error — a fresh install has no profiles yet.

func (*Store) Save

func (s *Store) Save(profiles map[string]*Profile, defaultProfile string) error

Save atomically writes profiles + defaultProfile back to disk with mode 0600 on POSIX. Atomicity is via tempfile + rename in the same directory.

Jump to

Keyboard shortcuts

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