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)
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"AllowFreshAdminGeneration": true,
|
||||
"AdminEmails": ["admin@admin.invalid"],
|
||||
"AdminHmacEnv": "ADMIN_HMAC_ENV",
|
||||
"UserHmacEnv": "USER_HMAC_ENV",
|
||||
"AuthedRateLimitConfig": "ratelimit.auth.json",
|
||||
"UnauthedRateLimitConfig": "ratelimit.unauth.json",
|
||||
|
||||
"DbDialect": "sqlite",
|
||||
"DbUrl": "prepack.db",
|
||||
"DbUsername": "",
|
||||
"DbPasswordSecret": "",
|
||||
"DbPort": "",
|
||||
"DbName": ""
|
||||
}
|
||||
13
config/dev/conf.toml
Normal file
13
config/dev/conf.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
AllowFreshAdminGeneration = true
|
||||
AdminEmails = ["admin@admin.invalid"]
|
||||
AdminHmacEnv = "ADMIN_HMAC_ENV"
|
||||
UserHmacEnv = "USER_HMAC_ENV"
|
||||
AuthedRateLimitConfig = "ratelimit.auth.json"
|
||||
UnauthedRateLimitConfig = "ratelimit.unauth.json"
|
||||
|
||||
DbDialect = "sqlite"
|
||||
DbUrl = "prepack.db"
|
||||
DbUsername = ""
|
||||
DbPasswordSecret = ""
|
||||
DbPort = ""
|
||||
DbName = ""
|
||||
Reference in New Issue
Block a user