From e0f66b8237120489f73ea7166ed8a909159fa066 Mon Sep 17 00:00:00 2001 From: carabasdaniel Date: Fri, 24 Nov 2023 15:58:23 +0200 Subject: [PATCH] Allow viper automatic env vars with AUTH0_GW prefix --- pkg/config/config.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/config/config.go b/pkg/config/config.go index 54c034b..8245baa 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -1,6 +1,7 @@ package config import ( + "strings" "time" "github.com/mitchellh/mapstructure" @@ -55,12 +56,17 @@ func Load(file string) (*Config, error) { v.AddConfigPath(".") v.SetConfigFile(file) + v.SetEnvPrefix("AUTH0_GW") + v.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + v.SetDefault("scheduler.interval", "5m") if err := v.ReadInConfig(); err != nil { return nil, errors.Wrapf(err, "loading config file %s", file) } + v.AutomaticEnv() + cfg := &Config{} err := v.UnmarshalExact(cfg, func(dc *mapstructure.DecoderConfig) { dc.TagName = "json"