fix: unify DATA_DIR default to /var/lib/webhooker for all environments
All checks were successful
check / check (push) Successful in 1m4s
All checks were successful
check / check (push) Successful in 1m4s
Remove devDataDir() XDG-based logic. Both dev and prod now default DATA_DIR to /var/lib/webhooker. Update Dockerfile and README to match.
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -80,23 +79,6 @@ func envInt(key string, defaultValue int) int {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// devDataDir returns the default data directory for the dev
|
||||
// environment. It uses $XDG_DATA_HOME/webhooker if set, otherwise
|
||||
// falls back to $HOME/.local/share/webhooker. The result is always
|
||||
// an absolute path so the application's behavior does not depend on
|
||||
// the working directory.
|
||||
func devDataDir() string {
|
||||
if xdg := os.Getenv("XDG_DATA_HOME"); xdg != "" {
|
||||
return filepath.Join(xdg, "webhooker")
|
||||
}
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
// Last resort: use /tmp so we still have an absolute path.
|
||||
return filepath.Join(os.TempDir(), "webhooker")
|
||||
}
|
||||
return filepath.Join(home, ".local", "share", "webhooker")
|
||||
}
|
||||
|
||||
// nolint:revive // lc parameter is required by fx even if unused
|
||||
func New(lc fx.Lifecycle, params ConfigParams) (*Config, error) {
|
||||
log := params.Logger.Get()
|
||||
@@ -127,16 +109,11 @@ func New(lc fx.Lifecycle, params ConfigParams) (*Config, error) {
|
||||
params: ¶ms,
|
||||
}
|
||||
|
||||
// Set default DataDir based on environment. All SQLite databases
|
||||
// (main application DB and per-webhook event DBs) live here.
|
||||
// Both defaults are absolute paths to avoid dependence on the
|
||||
// working directory.
|
||||
// Set default DataDir. All SQLite databases (main application DB
|
||||
// and per-webhook event DBs) live here. The same default is used
|
||||
// regardless of environment; override with DATA_DIR if needed.
|
||||
if s.DataDir == "" {
|
||||
if s.IsProd() {
|
||||
s.DataDir = "/data"
|
||||
} else {
|
||||
s.DataDir = devDataDir()
|
||||
}
|
||||
s.DataDir = "/var/lib/webhooker"
|
||||
}
|
||||
|
||||
if s.Debug {
|
||||
|
||||
Reference in New Issue
Block a user