parse []string from env

main
Bel LaPointe 2024-04-12 13:57:53 -06:00
parent a7e254ff94
commit a8d1d69f63
2 changed files with 9 additions and 1 deletions

View File

@ -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)
}
}

View File

@ -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)
}
}