From 7195382b7af280febedc9a62ec572ce81a28d8af Mon Sep 17 00:00:00 2001 From: riomoo Date: Sun, 18 Jan 2026 13:37:30 -0500 Subject: [PATCH] ENV Variables --- app/gopherbook/config.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 app/gopherbook/config.go diff --git a/app/gopherbook/config.go b/app/gopherbook/config.go new file mode 100644 index 0000000..08e6ff5 --- /dev/null +++ b/app/gopherbook/config.go @@ -0,0 +1,39 @@ +package main + +import ( + "os" + "path/filepath" +) + +// initializePaths sets up the directory paths based on environment variables +// or falls back to defaults. This should be called before any path is used. +func init() { + // Library path - where comic files are stored + if envPath := os.Getenv("GOPHERBOOK_LIBRARY_PATH"); envPath != "" { + libraryPath = envPath + } + + // Cache path - where cover thumbnails are cached + if envPath := os.Getenv("GOPHERBOOK_CACHE_PATH"); envPath != "" { + cachePath = envPath + } + + // Config/etc path - where user data and settings are stored + if envPath := os.Getenv("GOPHERBOOK_CONFIG_PATH"); envPath != "" { + etcPath = envPath + } + + // Watch path - where files are auto-imported from + if envPath := os.Getenv("GOPHERBOOK_WATCH_PATH"); envPath != "" { + watchPath = envPath + } + + // Data root - if set, use this as base for all paths + // This is useful for XDG compliance or systemd DynamicUser + if dataRoot := os.Getenv("GOPHERBOOK_DATA_ROOT"); dataRoot != "" { + libraryPath = filepath.Join(dataRoot, "library") + cachePath = filepath.Join(dataRoot, "cache", "covers") + etcPath = filepath.Join(dataRoot, "etc") + watchPath = filepath.Join(dataRoot, "watch") + } +}