hivedav

A curlable free/busy scheduler with CalDAV integration
git clone https://git.in0rdr.ch/hivedav.git
Log | Files | Refs | Pull requests |Archive | README | LICENSE

commit b0d27e34a236232739557b64b35ca7954bd29ef5
parent d08def228f6b05aeec76130dcd285f6b9f24312c
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Mon, 18 Sep 2023 00:40:24 +0200

fix(config): env var overrides config file

Diffstat:
Mconfig/config.go | 29+++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/config/config.go b/config/config.go @@ -21,10 +21,6 @@ func (c *Config) LoadConfig(path string) (*Config, error) { // look for config file with name "app.env" viper.SetConfigType("env") - // override config file vars with env vars - viper.AutomaticEnv() - viper.SetEnvPrefix("HIVEDAV") - // define some defaults viper.SetDefault("HIVEDAV_LISTEN_PORT", 3737) viper.SetDefault("HIVEDAV_LISTEN_ADDRESS", "[::]") @@ -41,5 +37,30 @@ func (c *Config) LoadConfig(path string) (*Config, error) { log.Println("Error unmarshalling config") return nil, err } + + viper.SetEnvPrefix("HIVEDAV") + // we either need AutomaticEnv() or BindEnv() on each var + viper.AutomaticEnv() + + // override config file vars with vars from environment + if viper.IsSet("LISTEN_ADDRESS") { + c.ListenAddress = viper.GetString("LISTEN_ADDRESS") + } + if viper.IsSet("LISTEN_PORT") { + c.ListenPort = viper.GetInt("LISTEN_PORT") + } + if viper.IsSet("CALDAV_URI") { + c.CaldavUri = viper.GetString("CALDAV_URI") + } + if viper.IsSet("CALENDAR") { + c.Calendar = viper.GetInt("CALENDAR") + } + if viper.IsSet("CALDAV_USER") { + c.CaldavUser = viper.GetString("CALDAV_USER") + } + if viper.IsSet("CALDAV_PASSWORD") { + c.CaldavPassword = viper.GetString("CALDAV_PASSWORD") + } + return c, nil }