Documentation
¶
Overview ¶
Package configstore bridges the config package and the sqlite repository so CLI, GUI, and webserver share a single implementation of the open-database → migrate → load/save flow that used to be duplicated across cmd/upbrr/main.go and internal/guiapp/config.go.
Index ¶
- Constants
- func Bootstrap(ctx context.Context, configPath string, configProvided, persistYAML bool) (config.Config, string, error)
- func BootstrapWithValidator(ctx context.Context, configPath string, configProvided, persistYAML bool, ...) (config.Config, string, error)
- func DefaultYAMLPath() (string, error)
- func LoadFromDBPath(ctx context.Context, dbPath string) (*config.Config, error)
- func LoadFromPathOrEmbedded(path string) (*config.Config, error)
- func ResolveYAMLPath(path string, provided bool) (string, error)
- func SaveToDBPath(ctx context.Context, cfg *config.Config, dbPath string) error
- func SaveToRepository(ctx context.Context, cfg *config.Config, repo *db.SQLiteRepository, ...) error
Constants ¶
const DefaultConfigFileName = "config.yaml"
DefaultConfigFileName is the default file name used when upbrr materializes a YAML config next to the database.
Variables ¶
This section is empty.
Functions ¶
func Bootstrap ¶
func Bootstrap(ctx context.Context, configPath string, configProvided, persistYAML bool) (config.Config, string, error)
Bootstrap resolves the effective config and database path at process startup. It prefers the sqlite database (with YAML used only as a bootstrap source when the database is empty). The persistYAML flag controls whether a YAML import is written back to the database. Callers that accept incomplete setup config can pass false or omit validation; CLI callers validate before saving so bad --config input cannot overwrite valid database state.
Environment overrides are applied to the returned runtime config but not to the config written to the database. This keeps the persisted state free of env-specific values so unsetting an env var later does not leave a stale override sitting in the database.
func BootstrapWithValidator ¶ added in v0.2.0
func BootstrapWithValidator(ctx context.Context, configPath string, configProvided, persistYAML bool, validateBeforePersist func(*config.Config) error) (config.Config, string, error)
BootstrapWithValidator is Bootstrap plus an optional validation hook for provided configs. The hook validates the exact config that would be persisted so environment-only fixes cannot write a config that fails after env removal. Without a hook, provided YAML/JSON is merged with stored DB config when present and persisted only if the persisted candidate validates.
func DefaultYAMLPath ¶
DefaultYAMLPath returns the default location for a YAML config file, colocated with the default sqlite database.
func LoadFromDBPath ¶
LoadFromDBPath opens the sqlite database at dbPath, runs migrations, loads the full configuration, backfills missing embedded defaults, disables unsupported tracker image rehosts, persists any load-time fixes back to the database, and applies environment overrides.
Callers decide whether to validate the returned config — the CLI fails fast while the web/GUI start with invalid config so users can fix it via the UI.
func LoadFromPathOrEmbedded ¶
LoadFromPathOrEmbedded reads the YAML file at path if it exists, otherwise returns the embedded default config. An empty path skips the file lookup.
func ResolveYAMLPath ¶
ResolveYAMLPath returns path when provided is true, falling back to DefaultYAMLPath otherwise. An empty provided path is an error.
func SaveToDBPath ¶
SaveToDBPath opens the sqlite database at dbPath, runs migrations, validates any web auth material, syncs cookie encryption metadata when auth material is usable, and persists the provided config. Malformed auth material and other cookie sync failures are returned before config or cookie metadata is saved.
func SaveToRepository ¶ added in v0.2.0
func SaveToRepository(ctx context.Context, cfg *config.Config, repo *db.SQLiteRepository, dbPath string) error
SaveToRepository persists cfg and cookie encryption auth metadata through one repository transaction.
Types ¶
This section is empty.