123
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"accounting-app/internal/config"
|
"accounting-app/internal/config"
|
||||||
@@ -20,13 +21,30 @@ func main() {
|
|||||||
filepath.Join("..", "..", ".env"), // Explicit path
|
filepath.Join("..", "..", ".env"), // Explicit path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var envDir string
|
||||||
for _, envPath := range envPaths {
|
for _, envPath := range envPaths {
|
||||||
if err := godotenv.Load(envPath); err == nil {
|
if err := godotenv.Load(envPath); err == nil {
|
||||||
log.Printf("Loaded environment from: %s", envPath)
|
log.Printf("Loaded environment from: %s", envPath)
|
||||||
|
envDir = filepath.Dir(envPath)
|
||||||
break
|
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
|
// Load configuration
|
||||||
cfg := config.Load()
|
cfg := config.Load()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user