config

package
v0.0.0-...-204b530 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package config persists the TUI's bearer token and server URL to a per-user TOML file under XDG_CONFIG_HOME.

The token is the only credential the TUI holds and is not recoverable if leaked, so the file is created with mode 0600 and the parent directory (which the OS may create) with 0700. The token is never logged.

Index

Constants

This section is empty.

Variables

View Source
var ErrMissing = errors.New("config: file does not exist")

ErrMissing is returned by Load when the config file doesn't exist. The caller treats this as a first-run signal and prompts the user for token + server URL.

Functions

func Path

func Path() (string, error)

Path returns the canonical config path: $XDG_CONFIG_HOME/plient/config.toml, falling back to $HOME/.config/plient/config.toml. An empty $HOME yields an error so we never silently write to the working directory.

func Save

func Save(path string, cfg Config) error

Save writes cfg to path atomically (write to a temp file, then rename). Both the file and its parent directory are created with restrictive permissions (0600 / 0700) so a careless backup tool can't widen access.

Types

type Config

type Config struct {
	// ServerURL is the posta-server origin (e.g. "https://arne.posta.no").
	// No trailing slash; the api package appends `/api/v1/...`.
	ServerURL string `toml:"server_url"`
	// Token is the plaintext bearer (mst_…) minted by `posta-server token
	// create`. Stored verbatim because it's already opaque server-side.
	Token string `toml:"token"`
	// LastEventID is the most recent SSE id observed at clean shutdown,
	// used as Last-Event-ID on the next start. Optional.
	LastEventID string `toml:"last_event_id,omitempty"`
}

Config is the on-disk shape.

func Load

func Load(path string) (Config, error)

Load reads and parses the config file. Returns ErrMissing if the file doesn't exist (the caller treats that as a first-run signal). Returns a wrapped error for any other I/O or parse problem.

Jump to

Keyboard shortcuts

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