From 08bf952988d45491a137c9f1eb98f8efccefe85d Mon Sep 17 00:00:00 2001 From: Tamas Gal Date: Thu, 16 Oct 2025 15:55:43 +0200 Subject: [PATCH] Env variables added --- backend/go.mod | 1 + backend/go.sum | 2 ++ backend/main.go | 15 +++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/backend/go.mod b/backend/go.mod index ee7b99e..167d824 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -13,6 +13,7 @@ require ( require ( github.com/dustin/go-humanize v1.0.1 // indirect github.com/google/uuid v1.6.0 // indirect + github.com/joho/godotenv v1.5.1 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/ncruces/go-strftime v0.1.9 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect diff --git a/backend/go.sum b/backend/go.sum index 20a340a..41e20da 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -10,6 +10,8 @@ github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17k github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= diff --git a/backend/main.go b/backend/main.go index b37ce95..4cbb247 100644 --- a/backend/main.go +++ b/backend/main.go @@ -6,10 +6,13 @@ import ( "fmt" "log" "net/http" + "os" "strconv" "strings" "time" + "github.com/joho/godotenv" + "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" "github.com/go-chi/cors" @@ -1017,6 +1020,18 @@ func server(app *App) *http.Server { } func main() { + err := godotenv.Load() + if err != nil { + log.Println("Cannot find .env file, using system env variables") + } + + adminUser := os.Getenv("ADMIN_USER") + adminPass := os.Getenv("ADMIN_PASS") + + if adminUser == "" || adminPass == "" { + log.Fatal("No ADMIN_USER or ADMIN_PASS env variable set") + } + db := database() defer db.Close()