parse []string from env
This commit is contained in:
@@ -17,7 +17,7 @@ type Config struct {
|
|||||||
Debug bool
|
Debug bool
|
||||||
InitializeSlack bool
|
InitializeSlack bool
|
||||||
SlackToken string
|
SlackToken string
|
||||||
SlackChannels string
|
SlackChannels []string
|
||||||
PostgresConn string
|
PostgresConn string
|
||||||
BasicAuthUser string
|
BasicAuthUser string
|
||||||
BasicAuthPassword string
|
BasicAuthPassword string
|
||||||
@@ -73,6 +73,10 @@ func newConfigFromEnv(ctx context.Context, getEnv func(string) string) (Config,
|
|||||||
return Config{}, err
|
return Config{}, err
|
||||||
}
|
}
|
||||||
m[k] = got
|
m[k] = got
|
||||||
|
case nil, []interface{}:
|
||||||
|
m[k] = strings.Split(s, ",")
|
||||||
|
default:
|
||||||
|
return Config{}, fmt.Errorf("not impl: parse %s as %T", envK, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ func TestNewConfig(t *testing.T) {
|
|||||||
return "1"
|
return "1"
|
||||||
case "INITIALIZE_SLACK":
|
case "INITIALIZE_SLACK":
|
||||||
return "true"
|
return "true"
|
||||||
|
case "SLACK_CHANNELS":
|
||||||
|
return "x,y"
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -22,5 +24,7 @@ func TestNewConfig(t *testing.T) {
|
|||||||
t.Error(got)
|
t.Error(got)
|
||||||
} else if !got.InitializeSlack {
|
} else if !got.InitializeSlack {
|
||||||
t.Error(got)
|
t.Error(got)
|
||||||
|
} else if len(got.SlackChannels) != 2 || got.SlackChannels[0] != "x" || got.SlackChannels[1] != "y" {
|
||||||
|
t.Error(got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user