Adding initial code for adding a new poll on the backend

This commit is contained in:
2025-11-04 16:39:10 -05:00
parent 3e2efae4ce
commit 5e8b4e2b61
8 changed files with 147 additions and 51 deletions

View File

@@ -14,6 +14,7 @@ type Config struct {
}
var conf *Config
var conf_path string = ".env"
func GetConfig() *Config {
if conf != nil {
@@ -23,7 +24,7 @@ func GetConfig() *Config {
conf = &Config{}
// TODO: Make this into a ini or toml file
confgContent, err := os.ReadFile(".env")
configContent, err := os.ReadFile(conf_path)
if err != nil {
fmt.Println("Error reading .env file: ", err)
@@ -37,10 +38,15 @@ func GetConfig() *Config {
for _, variable := range envVariables {
if strings.Contains(variable, "=") {
splitVariable := strings.Split(variable, "=")
envMap[splitVariable[0]] = splitVAriable[1]
envMap[splitVariable[0]] = splitVariable[1]
}
}
if err := json.Unmarshal([]byte(configContent), conf); err != nil {
fmt.Println("Error unmarshalling config file: ", err)
os.Exit(1)
}
// TODO: Better mapping of key to json values
// TODO: Better error checking if values are missing
// TODO: Default values
@@ -59,6 +65,6 @@ func GetConfig() *Config {
return conf
}
func init() {
conf = GetConfig()
func SetConfig(init_conf *Config) {
conf = init_conf
}