From ead10cc1095b76dbd370f60a34565881373ad759 Mon Sep 17 00:00:00 2001 From: jp Date: Tue, 18 Jun 2024 17:55:12 +0200 Subject: [PATCH] renaming of handler file + env file example + utility for env file reading --- .env.example | 2 ++ handlers/{auth.handler.go => auth.go} | 0 handlers/{dashboard.handler.go => dashboard.go} | 0 handlers/status.go | 8 ++++++++ server/main.go | 9 +++++++++ utils/env_reader.go | 10 ++++++++++ 6 files changed, 29 insertions(+) create mode 100644 .env.example rename handlers/{auth.handler.go => auth.go} (100%) rename handlers/{dashboard.handler.go => dashboard.go} (100%) create mode 100644 handlers/status.go create mode 100644 utils/env_reader.go diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..337c30f --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +SOARCA_URI: http://localhost:8080 +GIN_MODE: "release" \ No newline at end of file diff --git a/handlers/auth.handler.go b/handlers/auth.go similarity index 100% rename from handlers/auth.handler.go rename to handlers/auth.go diff --git a/handlers/dashboard.handler.go b/handlers/dashboard.go similarity index 100% rename from handlers/dashboard.handler.go rename to handlers/dashboard.go diff --git a/handlers/status.go b/handlers/status.go new file mode 100644 index 0000000..0774149 --- /dev/null +++ b/handlers/status.go @@ -0,0 +1,8 @@ +package handlers + +import "github.com/gin-gonic/gin" + +type StatusHandler struct{} + +func (s *StatusHandler) StatusIndicator(context *gin.Context) { +} diff --git a/server/main.go b/server/main.go index 2e7764d..aa6e098 100644 --- a/server/main.go +++ b/server/main.go @@ -1,9 +1,12 @@ package main import ( + "fmt" + "soarca-gui/routes" "github.com/gin-gonic/gin" + "github.com/joho/godotenv" ) var ( @@ -12,6 +15,12 @@ var ( ) func main() { + errenv := godotenv.Load(".env") + + if errenv != nil { + fmt.Println("Failed to read env variable, but will continue") + } + app := gin.Default() routes.Setup(app) diff --git a/utils/env_reader.go b/utils/env_reader.go new file mode 100644 index 0000000..282a613 --- /dev/null +++ b/utils/env_reader.go @@ -0,0 +1,10 @@ +package utils + +import "os" + +func GetEnv(key, fallback string) string { + if value, ok := os.LookupEnv(key); ok { + return value + } + return fallback +}