config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: CC0-1.0 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 resolves Taskronin's configuration and filesystem paths.

Index

Constants

View Source
const MaxSocketPath = 107

MaxSocketPath leaves one byte for the NUL in Linux's 108-byte sun_path.

Variables

This section is empty.

Functions

func CheckSocketPath

func CheckSocketPath(p string) error

CheckSocketPath checks the encoded byte length, not the number of runes.

func OtherHumanAccounts

func OtherHumanAccounts(passwdPath string, myUID int) ([]string, error)

OtherHumanAccounts lists other accounts with UID >= 1000 and a login shell. An unreadable or malformed passwd file must not imply a single-user host.

func ScrubJournal

func ScrubJournal(backupDir string) string

ScrubJournal is the scrub recovery journal within the effective backup dir.

func ValidateClient

func ValidateClient(c *Client) error

ValidateClient checks client paths, time budgets and terminal color mode.

func ValidateServer

func ValidateServer(s *Server) error

ValidateServer checks configuration values. Listener consent is checked separately by WebListenerAllowed when a build starts the web listener.

func WriteClient

func WriteClient(path string, c *Client) error

WriteClient atomically writes client.toml with mode 0600 and string durations. The parent directory must already exist.

func WriteServer

func WriteServer(path string, s *Server) error

WriteServer atomically writes server.toml with mode 0600. The parent directory must already exist; init is responsible for creating private directories.

Types

type BackupConfig

type BackupConfig struct {
	Dir  string `toml:"dir"`
	Time string `toml:"time"`
}

BackupConfig gives the backup directory and daily time in the server zone.

type Client

type Client struct {
	Socket        string        `toml:"socket"`
	TokenFile     string        `toml:"token_file"`
	Timeout       time.Duration `toml:"timeout"`
	StatusTimeout time.Duration `toml:"status_timeout"`
	Editor        string        `toml:"editor"`
	Color         string        `toml:"color"`
	MCP           struct {
		TokenFile string `toml:"token_file"`
	} `toml:"mcp"`
}

Client is the client.toml schema. Missing keys keep DefaultClient values.

func DefaultClient

func DefaultClient(p Paths) *Client

DefaultClient supplies paths and time budgets for a missing client.toml.

func LoadClient

func LoadClient(path string, p Paths) (*Client, error)

LoadClient strictly decodes over defaults, or uses just those defaults if the file is missing. In either case the resulting configuration is validated.

func LoadClientWithOverrides

func LoadClientWithOverrides(path string, p Paths, overrides ClientOverrides) (*Client, error)

LoadClientWithOverrides validates the effective configuration, allowing a caller to replace an unusable configured path without using that path first.

type ClientOverrides

type ClientOverrides struct {
	Socket, TokenFile, Color string
}

ClientOverrides contains CLI flags that replace decoded values before validation. Empty strings leave the configured value or default unchanged.

type LogConfig

type LogConfig struct {
	Level  string `toml:"level"`
	Format string `toml:"format"`
}

LogConfig selects the slog level and output format.

type Paths

type Paths struct {
	ConfigDir, DataDir, StateDir, RuntimeDir                     string
	ServerConfig, ClientConfig, Socket, OwnerToken, TokensDir    string
	DraftsDir, PendingDir, StagingDir, BackupDir, LedgerFile, DB string
}

Paths contains the resolved locations of Taskronin's files and directories.

func DefaultPaths

func DefaultPaths(getenv func(string) string, home string) (Paths, error)

DefaultPaths resolves XDG paths without accessing the filesystem. Relative XDG values are ignored. An absolute home is required for any home fallback. Callers create and check private directories before using these paths.

func (Paths) LockFile

func (p Paths) LockFile() string

LockFile is the instance lock shared by the server and offline commands.

func (Paths) SwapJournal

func (p Paths) SwapJournal() string

SwapJournal is the recovery journal for a database swap.

func (Paths) TokenFile

func (p Paths) TokenFile(name string) string

TokenFile returns the token path for an already-validated token name.

func (Paths) UnitsDir

func (p Paths) UnitsDir() string

UnitsDir is the systemd user unit directory under the XDG config home.

func (Paths) WithServerPaths

func (p Paths) WithServerPaths(dataDir, socket, backupDir string) Paths

WithServerPaths returns paths rebased to the effective server configuration. All three arguments must be fully resolved, validated configuration values; empty arguments do not mean "keep the default".

type Server

type Server struct {
	Timezone    string       `toml:"timezone"`
	WeekStart   string       `toml:"week_start"`
	DueSoonDays int          `toml:"due_soon_days"`
	Paths       ServerPaths  `toml:"paths"`
	Web         WebConfig    `toml:"web"`
	Backup      BackupConfig `toml:"backup"`
	Log         LogConfig    `toml:"log"`
}

Server is the server.toml schema. Paths are resolved by init; loading a configuration does not create directories or change their permissions.

func DefaultServer

func DefaultServer(p Paths, timezone string) *Server

DefaultServer builds init's defaults without granting plain HTTP consent.

func LoadServer

func LoadServer(path string) (*Server, error)

LoadServer strictly decodes and validates an existing server configuration. Before using files, server/offline callers must rebase their Paths with p.WithServerPaths(s.Paths.DataDir, s.Paths.Socket, s.Backup.Dir) (BF01).

func (*Server) BackupMinute

func (s *Server) BackupMinute() (civil.Minute, error)

BackupMinute parses the daily backup time, excluding 24:00.

func (*Server) WebAddr

func (s *Server) WebAddr() (netip.AddrPort, error)

WebAddr parses a numeric loopback address and port without resolving DNS. The one accepted hostname, localhost, always maps to IPv4 loopback.

func (*Server) WebListenerAllowed

func (s *Server) WebListenerAllowed() error

WebListenerAllowed requires explicit consent before serving plain HTTP.

func (*Server) WeekStartDay

func (s *Server) WeekStartDay() (time.Weekday, error)

WeekStartDay returns the weekday selected by the lowercase configuration name.

func (*Server) Zone

func (s *Server) Zone() (civil.Zone, error)

Zone loads the configured IANA timezone.

type ServerPaths

type ServerPaths struct {
	DataDir string `toml:"data_dir"`
	Socket  string `toml:"socket"`
}

ServerPaths contains the effective server data directory and socket path.

type TokenFileError

type TokenFileError struct {
	Path string
	Err  error
}

TokenFileError identifies token path failures during configuration validation, before the client can check the credential file itself.

func (*TokenFileError) Error

func (e *TokenFileError) Error() string

func (*TokenFileError) Unwrap

func (e *TokenFileError) Unwrap() error

Unwrap preserves the path validation failure.

type WebConfig

type WebConfig struct {
	Enabled            bool   `toml:"enabled"`
	Listen             string `toml:"listen"`
	AllowPlainLoopback bool   `toml:"allow_plain_loopback"`
}

WebConfig controls the optional plain HTTP loopback listener.

Jump to

Keyboard shortcuts

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