This commit is contained in:
2026-02-02 11:20:17 +08:00
parent 2e869e0c85
commit 0d3f3cd811

View File

@@ -2,6 +2,7 @@ package main
import (
"log"
"os"
"path/filepath"
"accounting-app/internal/config"
@@ -20,13 +21,30 @@ func main() {
filepath.Join("..", "..", ".env"), // Explicit path
}
var envDir string
for _, envPath := range envPaths {
if err := godotenv.Load(envPath); err == nil {
log.Printf("Loaded environment from: %s", envPath)
envDir = filepath.Dir(envPath)
break
}
}
// Load specific environment file if APP_ENV is set (e.g. .env.dev, .env.prod)
if appEnv := os.Getenv("APP_ENV"); appEnv != "" {
targetEnvFile := ".env." + appEnv
targetEnvPath := targetEnvFile
if envDir != "" && envDir != "." {
targetEnvPath = filepath.Join(envDir, targetEnvFile)
}
if err := godotenv.Overload(targetEnvPath); err == nil {
log.Printf("Loaded specific environment config from: %s", targetEnvPath)
} else {
log.Printf("Note: Specific environment file %s not found or could not be loaded", targetEnvPath)
}
}
// Load configuration
cfg := config.Load()