From a8d1d69f63268db5db3f269e67f161623e7633ee Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:57:53 -0600 Subject: [PATCH] parse []string from env --- config.go | 6 +++++- config_test.go | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index 61ed430..ffb707b 100644 --- a/config.go +++ b/config.go @@ -17,7 +17,7 @@ type Config struct { Debug bool InitializeSlack bool SlackToken string - SlackChannels string + SlackChannels []string PostgresConn string BasicAuthUser string BasicAuthPassword string @@ -73,6 +73,10 @@ func newConfigFromEnv(ctx context.Context, getEnv func(string) string) (Config, return Config{}, err } m[k] = got + case nil, []interface{}: + m[k] = strings.Split(s, ",") + default: + return Config{}, fmt.Errorf("not impl: parse %s as %T", envK, v) } } diff --git a/config_test.go b/config_test.go index f4a5a99..62527b5 100644 --- a/config_test.go +++ b/config_test.go @@ -13,6 +13,8 @@ func TestNewConfig(t *testing.T) { return "1" case "INITIALIZE_SLACK": return "true" + case "SLACK_CHANNELS": + return "x,y" default: return "" } @@ -22,5 +24,7 @@ func TestNewConfig(t *testing.T) { t.Error(got) } else if !got.InitializeSlack { t.Error(got) + } else if len(got.SlackChannels) != 2 || got.SlackChannels[0] != "x" || got.SlackChannels[1] != "y" { + t.Error(got) } }