BUGFIX: read XML data

This commit is contained in:
Simon Martens
2025-03-13 18:31:09 +01:00
parent e839bbebe8
commit f85dbab551
9 changed files with 105 additions and 28 deletions

View File

@@ -17,8 +17,10 @@ const (
DEFAULT_SEARCH_CACHE_DIR = "search"
DEFAULT_IMG_DIR = "data_bilder"
DEFAULT_BRANCH = "main"
DEFAULT_PORT = "8080"
DEFAULT_ADDR = "localhost"
DEFAULT_ADDR = "127.0.0.1"
DEFAULT_HTTPS = false
ENV_PREFIX = "KGPZ"
@@ -55,7 +57,7 @@ func NewConfigProvider(files []string) *ConfigProvider {
func (c *ConfigProvider) Read() error {
c.Config = &Config{}
for _, file := range c.Files {
c.Config = readSettingsFile(c.Config, file)
_, _ = readSettingsFile(c.Config, file)
}
c.Config = readSettingsEnv(c.Config)
c.Config = readDefaults(c.Config)
@@ -69,17 +71,17 @@ func (c *ConfigProvider) Validate() error {
return nil
}
func readSettingsFile(cfg *Config, path string) *Config {
func readSettingsFile(cfg *Config, path string) (*Config, error) {
f, err := os.Open(path)
if err != nil {
return cfg
return cfg, err
}
defer f.Close()
dec := json.NewDecoder(f)
err = dec.Decode(cfg)
return cfg
return cfg, err
}
func readSettingsEnv(cfg *Config) *Config {
@@ -92,6 +94,10 @@ func readDefaults(cfg *Config) *Config {
cfg.BaseDIR = DEFAULT_DIR
}
if strings.TrimSpace(cfg.GitBranch) == "" {
cfg.GitBranch = DEFAULT_BRANCH
}
if strings.TrimSpace(cfg.GITPath) == "" {
cfg.GITPath = DEFAULT_GIT_CACHE_DIR
}