config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 7 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 loads shelf's TOML configuration and resolves the XDG directories shelf reads and writes.

Index

Constants

View Source
const (
	MinChunkSize     = 4 * 1024
	MaxChunkSize     = 15 * 1024
	DefaultChunkSize = 8 * 1024
)

Chunk size bounds. The device runs on an ESP32-C3 with roughly 380 KB of usable RAM and a 4 KB write buffer, so oversized chunks are a real failure mode rather than a tuning inefficiency.

These mirror internal/device: the device refuses frames above ~15 KB, so a config that validated a larger value would pass here and fail at upload.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	LibraryRoot    string `toml:"library_root"`
	Inbox          string `toml:"inbox"`
	NamingTemplate string `toml:"naming_template"`

	UI      UI       `toml:"ui"`
	Kosync  Kosync   `toml:"kosync"`
	OPDS    OPDS     `toml:"opds"`
	Devices []Device `toml:"device"`
	Convert Convert  `toml:"convert"`
	Sync    Sync     `toml:"sync"`

	// Paths is resolved at load time, not read from the file.
	Paths Paths `toml:"-"`
}

Config is the parsed contents of config.toml.

func Default

func Default() Config

Default returns the configuration shelf uses when no file exists.

func Load

func Load() (Config, error)

Load reads config.toml from the standard location. A missing file is not an error: shelf works out of the box against ~/Books.

func LoadFile

func LoadFile(file string, paths Paths) (Config, error)

LoadFile reads a specific config file. Exported so tests and --config can point at an arbitrary path.

func (*Config) DeviceByName

func (c *Config) DeviceByName(name string) (Device, error)

DeviceByName returns the named device, or the only configured device when name is empty. Ambiguity is an error rather than a silent guess: picking the wrong device means writing books to hardware the user did not mean.

func (*Config) DeviceNames

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

DeviceNames lists configured device nicknames in file order.

func (*Config) Validate

func (c *Config) Validate() error

Validate rejects configurations that would fail confusingly later.

type Convert

type Convert struct {
	PDF     string   `toml:"pdf"`
	Timeout Duration `toml:"timeout"`
}

Convert configures the conversion pipeline.

type Device

type Device struct {
	Nickname  string    `toml:"nickname"`
	Host      string    `toml:"host"` // empty triggers discovery
	Root      string    `toml:"root"` // device-side path, always forward-slash
	Transport Transport `toml:"transport"`
	ChunkSize int       `toml:"chunk_size"`
	Optimize  bool      `toml:"optimize"`
	Profile   string    `toml:"profile"`
	Mount     string    `toml:"mount"` // SD transport only
}

Device describes one configured e-reader.

type Duration

type Duration struct{ time.Duration }

Duration wraps time.Duration so TOML can carry human strings like "150ms".

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler for TOML decoding.

type Kosync

type Kosync struct {
	// User is whose progress the library table shows. Empty disables the
	// percentage column rather than guessing between accounts.
	User string `toml:"user"`
	// Listen is the default address for `shelf serve`.
	Listen string `toml:"listen"`
}

Kosync configures reading-progress sync.

The device pushes progress to a kosync server; shelf runs one with `shelf serve` and reads from the same store to show percentages.

type OPDS

type OPDS struct {
	// Title names the catalog in the reader's server list and in every feed.
	Title string `toml:"title"`
	// PageSize is how many entries a feed carries. Clamped to what the
	// firmware's parser will actually read; see internal/opds/compat.go.
	PageSize int `toml:"page_size"`
	// Anonymous serves the catalog without a password. Off by default: the
	// listener binds to every interface, and the accounts already exist.
	Anonymous bool `toml:"anonymous"`
	// Disabled turns the catalog off, leaving progress sync running.
	Disabled bool `toml:"disabled"`
}

OPDS configures the catalog served by `shelf serve`.

type Paths

type Paths struct {
	Config string // config.toml, shelves.toml
	Data   string // index.db
	State  string // devices/<uuid>.json, shelf.log
	Cache  string // optimized/, cover thumbnails
}

Paths resolves every directory shelf writes to.

func DefaultPaths

func DefaultPaths() (Paths, error)

DefaultPaths resolves the standard locations for the current user.

func (Paths) ConfigFile

func (p Paths) ConfigFile() string

ConfigFile is the path to config.toml.

func (Paths) DeviceStateDir

func (p Paths) DeviceStateDir() string

DeviceStateDir holds per-device sync manifests, one JSON file per device UUID.

func (Paths) DeviceStateFile

func (p Paths) DeviceStateFile(uuid string) string

DeviceStateFile is the local manifest for a single device.

func (Paths) EnsureDirs

func (p Paths) EnsureDirs() error

EnsureDirs creates every directory shelf writes to.

func (Paths) IndexFile

func (p Paths) IndexFile() string

IndexFile is the derived SQLite cache.

func (Paths) LogFile

func (p Paths) LogFile() string

LogFile is where shelf logs; never stdout, which belongs to the display.

func (Paths) OptimizedDir

func (p Paths) OptimizedDir() string

OptimizedDir caches device-targeted EPUB builds, keyed by (sha256, profile).

func (Paths) ProgressFile

func (p Paths) ProgressFile() string

ProgressFile is the reading-progress store.

Under Data rather than Cache deliberately: unlike index.db, this cannot be rebuilt from anything. The device pushes reading positions here and keeps no synchronised copy, so deleting it loses where you are in every book.

func (Paths) ShelvesFile

func (p Paths) ShelvesFile() string

ShelvesFile is the authoritative, human-editable record of shelf definitions. The SQLite index is a cache and may be deleted at any time; this file is the one piece of state that cannot be reconstructed by rescanning the library.

type Sync

type Sync struct {
	InterOpDelay Duration `toml:"inter_op_delay"`
	MaxRetries   int      `toml:"max_retries"`
	Prune        bool     `toml:"prune"`
}

Sync tunes the transfer executor.

type Transport

type Transport string

Transport selects how shelf moves bytes to a device.

const (
	TransportWS     Transport = "ws"     // WebSocket on :81, the primary path
	TransportHTTP   Transport = "http"   // POST /upload multipart
	TransportWebDAV Transport = "webdav" // PUT; designed in spec.md, not implemented
	TransportSD     Transport = "sd"     // direct SD-card mount
)

type UI

type UI struct {
	Theme    string `toml:"theme"`    // auto | light | dark
	Graphics string `toml:"graphics"` // auto | kitty | sixel | ascii | none
}

UI holds presentation preferences. Unused until the TUI lands in M3, but parsed now so an existing config file does not start erroring later.

Jump to

Keyboard shortcuts

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