Updating config to TOML (JSON sucks! I hate it! We shouldn't use it!)

This commit is contained in:
🐙PiperYxzzy
2025-10-13 20:23:06 +02:00
parent 0f93876c8b
commit acd23c2f45
6 changed files with 32 additions and 21 deletions

View File

@@ -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)
}