Skip to content

Commit

Permalink
Merge pull request #9 from capstone-kelompok-7/bugfix/load-env
Browse files Browse the repository at this point in the history
bugfix:load env
  • Loading branch information
masnann authored Nov 8, 2023
2 parents 0d16102 + 69f5dd0 commit 205ae26
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package config

import (
"github.com/joho/godotenv"
"log"
"os"
"strconv"

"github.com/joho/godotenv"
)

type Config struct {
Expand All @@ -21,22 +22,19 @@ func InitConfig() *Config {
var res = new(Config)
res = loadConfig()

if res == nil {
log.Fatal("Config : cannot load configuration")
return nil
}
return res

}

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 {
Expand Down

0 comments on commit 205ae26

Please sign in to comment.