Upgrades to Config

* Added config file and config tests
* Configs per stack can be set up depending on their config/STACK folder
and tested appropriately to add config redundancy
This commit is contained in:
🐙PiperYxzzy
2022-08-14 12:55:11 +02:00
parent b198814aa7
commit 9cc37b0d0d
9 changed files with 170 additions and 14 deletions

View File

@@ -2,21 +2,37 @@ package config
import (
"encoding/json"
"log"
"os"
)
type StackConfiguration struct {
ConfigLoaded bool
ConfigLoaded bool
AllowFreshAdminGeneration bool
AdminEmails []string
AdminHmacEnv string
UserHmacEnv string
AuthedRateLimitConfig string
UnauthedRateLimitConfig string
}
var Environment = os.Getenv("STACK_ENVIRONMENT")
var Config = StackConfiguration{}
func GetConfigPath(filename string) string {
if Environment == "" {
Environment = "dev"
}
return Environment + "/" + filename
}
func LoadConfig() {
file, _ := os.Open("conf.json")
file, err := os.Open(GetConfigPath("conf.json"))
if err != nil {
panic(err)
}
defer file.Close()
dec := json.NewDecoder(file)
if err := dec.Decode(&Config); err != nil {
@@ -24,4 +40,6 @@ func LoadConfig() {
}
Config.ConfigLoaded = true
log.Printf("Loaded Config for stack " + Environment)
}