don't remember what this does lol

This commit is contained in:
2023-10-28 21:17:05 +01:00
parent 8f0cf776b1
commit 749a3bc9b3
6 changed files with 51 additions and 24 deletions

View File

@@ -1,5 +1,12 @@
package config
import (
"encoding/json"
"io/ioutil"
"gopkg.in/yaml.v3"
)
// The struct that represents the config.json file
type Config struct {
ListenAddress string
@@ -33,3 +40,23 @@ func (c Config) Validate() error {
return nil
}
func (c *Config) Load(config_filename string) error {
raw_config, err := ioutil.ReadFile(config_filename)
if err != nil {
return err
}
err = json.Unmarshal(raw_config, &c)
if err == nil {
return c.Validate()
}
err = yaml.Unmarshal(raw_config, &c)
if err == nil {
return c.Validate()
}
return err
}