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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user