ENV Variables

This commit is contained in:
riomoo 2026-01-18 13:37:30 -05:00
parent 44b2874780
commit 7195382b7a
Signed by: riomoo
SSH key fingerprint: SHA256:dP5B5iLpXU5V8aBA8eGm9tN5YtxXJybnv4McyltPyzM

39
app/gopherbook/config.go Normal file
View file

@ -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")
}
}