From 0b2abac6282930e56f896ed57a352f653fce50ec Mon Sep 17 00:00:00 2001 From: Zeni Kim Date: Tue, 29 Oct 2024 06:48:11 -0500 Subject: [PATCH] add prod mode --- .gitignore | 1 + main.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 84146d5..6040264 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .air.toml .env +.env-dev tmp/* logs/* !logs/.gitkeep diff --git a/main.go b/main.go index fd1f7b4..4b9c956 100644 --- a/main.go +++ b/main.go @@ -26,14 +26,25 @@ var resources embed.FS func main() { app := core.New() basePath, err := os.Getwd() + runMode := "dev" + if len(os.Args) > 1 { + if os.Args[1] == "prod" || os.Args[1] == "dev" { + runMode = os.Args[1] + } + } if err != nil { log.Fatal("error getting current working dir") } app.SetBasePath(basePath) + app.SetRunMode(runMode) app.MakeDirs("logs", "storage", "storage/sqlite", "tls") // Handle the reading of the .env file if config.GetEnvFileConfig().UseDotEnvFile { - envVars, err := godotenv.Read(".env") + envfile := ".env-dev" + if runMode == "prod" { + envfile = ".env" + } + envVars, err := godotenv.Read(envfile) if err != nil { log.Fatal("Error loading .env file") }