Skip to content

Commit

Permalink
Fixed config issue
Browse files Browse the repository at this point in the history
  • Loading branch information
EliasB-NU committed Jun 4, 2024
1 parent 5a30bc3 commit dde8642
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions src/config/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package config

import (
"encoding/json"
"log"
"os"
)

Expand All @@ -23,34 +21,34 @@ type CFG struct {
ProjectName string `json:"Project"`
}

// func GetConfig() *CFG {
// var c CFG
// c.DB.Host = "db"
// c.DB.Port = 5432
// c.DB.Username = os.Getenv("DBUser")
// c.DB.Password = os.Getenv("DBPassword")
// c.DB.Database = os.Getenv("Database")
// c.Website.Host = "0.0.0.0"
// c.Website.Port = 80
// c.ProjectName = os.Getenv("ProjectName")

// return &c
// }
func GetConfig() *CFG {
var c CFG
c.DB.Host = "db"
c.DB.Port = 5432
c.DB.Username = os.Getenv("DBUser")
c.DB.Password = os.Getenv("DBPassword")
c.DB.Database = os.Getenv("Database")
c.Website.Host = "0.0.0.0"
c.Website.Port = 80
c.ProjectName = os.Getenv("ProjectName")

return &c
}

// Enable for local testing without docker container

func GetConfig() *CFG {
const file = "config/config.json"
var config CFG
// func GetConfig() *CFG {
// const file = "config/config.json"
// var config CFG

cfgfile, err := os.Open(file)
if err != nil {
log.SetFlags(log.LstdFlags | log.Lshortfile)
log.Fatalf("Error readeing config file: %d\n", err)
}
// cfgfile, err := os.Open(file)
// if err != nil {
// log.SetFlags(log.LstdFlags | log.Lshortfile)
// log.Fatalf("Error readeing config file: %d\n", err)
// }

jsonParser := json.NewDecoder(cfgfile)
jsonParser.Decode(&config)
// jsonParser := json.NewDecoder(cfgfile)
// jsonParser.Decode(&config)

return &config
}
// return &config
// }

0 comments on commit dde8642

Please sign in to comment.