Updating config to TOML (JSON sucks! I hate it! We shouldn't use it!)
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
type StackConfiguration struct {
|
||||
@@ -36,21 +38,27 @@ func GetConfigPath(filename string) string {
|
||||
if Environment == "" {
|
||||
Environment = "dev"
|
||||
}
|
||||
return Environment + "/" + filename
|
||||
return "config/" + Environment + "/" + filename
|
||||
}
|
||||
|
||||
func LoadConfig() {
|
||||
file, err := os.Open(GetConfigPath("conf.json"))
|
||||
file, err := os.Open(GetConfigPath("conf.toml"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer file.Close()
|
||||
dec := json.NewDecoder(file)
|
||||
if err := dec.Decode(&configInternal); err != nil {
|
||||
|
||||
b, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = toml.Unmarshal(b, &configInternal)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
configInternal.ConfigLoaded = true
|
||||
|
||||
log.Printf("Loaded Config for stack " + Environment)
|
||||
log.Printf("Loaded Config for stack '%s': %+v", Environment, configInternal)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user