From 69f5dd051cf5ad379382613892cc78adf3d46663 Mon Sep 17 00:00:00 2001 From: RianIhsan Date: Wed, 8 Nov 2023 16:45:01 +0700 Subject: [PATCH] bugfix:load env --- config/config.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/config/config.go b/config/config.go index 7776d2e..6a4b8d3 100644 --- a/config/config.go +++ b/config/config.go @@ -1,10 +1,11 @@ package config import ( - "github.com/joho/godotenv" "log" "os" "strconv" + + "github.com/joho/godotenv" ) type Config struct { @@ -21,10 +22,6 @@ func InitConfig() *Config { var res = new(Config) res = loadConfig() - if res == nil { - log.Fatal("Config : cannot load configuration") - return nil - } return res } @@ -32,11 +29,12 @@ func InitConfig() *Config { func loadConfig() *Config { var res = new(Config) - err := godotenv.Load(".env") - - if err != nil { - log.Fatal("Config : cannot load config file", err.Error()) - return nil + _, err := os.Stat(".env") + if err == nil { + err := godotenv.Load() + if err != nil { + log.Fatal("Failed to fetch .env file") + } } if value, found := os.LookupEnv("SERVER"); found {