refactor: move home env vars after godotenv and use lookupEnv helper
Address review feedback: move HOME_ADDR/HOME_PASSWORD lookup after godotenv.Load() so .env files work, and use the lookupEnv helper for case-insensitive key support consistent with PGSTORE_* etc. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+13
-12
@@ -247,18 +247,6 @@ func main() {
|
|||||||
// Parse the command-line flags.
|
// Parse the command-line flags.
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Allow env var fallback for home flags so they can be configured without command args.
|
|
||||||
if strings.TrimSpace(homeAddr) == "" {
|
|
||||||
if v, ok := os.LookupEnv("HOME_ADDR"); ok {
|
|
||||||
homeAddr = strings.TrimSpace(v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if strings.TrimSpace(homePassword) == "" {
|
|
||||||
if v, ok := os.LookupEnv("HOME_PASSWORD"); ok {
|
|
||||||
homePassword = strings.TrimSpace(v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Core application variables.
|
// Core application variables.
|
||||||
var err error
|
var err error
|
||||||
var cfg *config.Config
|
var cfg *config.Config
|
||||||
@@ -311,6 +299,19 @@ func main() {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
writableBase := util.WritablePath()
|
writableBase := util.WritablePath()
|
||||||
|
|
||||||
|
// Allow env var fallback for home flags so they can be configured without command args.
|
||||||
|
if strings.TrimSpace(homeAddr) == "" {
|
||||||
|
if v, ok := lookupEnv("HOME_ADDR", "home_addr"); ok {
|
||||||
|
homeAddr = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if strings.TrimSpace(homePassword) == "" {
|
||||||
|
if v, ok := lookupEnv("HOME_PASSWORD", "home_password"); ok {
|
||||||
|
homePassword = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if value, ok := lookupEnv("PGSTORE_DSN", "pgstore_dsn"); ok {
|
if value, ok := lookupEnv("PGSTORE_DSN", "pgstore_dsn"); ok {
|
||||||
usePostgresStore = true
|
usePostgresStore = true
|
||||||
pgStoreDSN = value
|
pgStoreDSN = value
|
||||||
|
|||||||
Reference in New Issue
Block a user