Skip to content

Commit 23cb8ef

Browse files
prizovAlexander Prizov
authored andcommitted
read env variables values from file (#408)
Co-authored-by: Alexander Prizov <alexander.prizov@ultimate.ai>
1 parent 5dcd3ff commit 23cb8ef

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

monstache.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,6 +2344,13 @@ func (config *configOptions) loadEnvironment() *configOptions {
23442344
if val == "" {
23452345
continue
23462346
}
2347+
if strings.HasSuffix(name, "__FILE") {
2348+
var err error
2349+
name, val, err = config.loadVariableValueFromFile(name, val)
2350+
if err != nil {
2351+
panic(err)
2352+
}
2353+
}
23472354
switch name {
23482355
case "MONSTACHE_MONGO_URL":
23492356
if config.MongoURL == "" {
@@ -2516,6 +2523,20 @@ func (config *configOptions) loadEnvironment() *configOptions {
25162523
return config
25172524
}
25182525

2526+
func (config *configOptions) loadVariableValueFromFile(name string, path string) (n string, v string, err error) {
2527+
name = strings.TrimSuffix(name, "__FILE")
2528+
f, err := os.Open(path)
2529+
if err != nil {
2530+
return name, "", fmt.Errorf("read value for %s from file failed: %s", name, err)
2531+
}
2532+
defer f.Close()
2533+
c, err := ioutil.ReadAll(f)
2534+
if err != nil {
2535+
return name, "", fmt.Errorf("read value for %s from file failed: %s", name, err)
2536+
}
2537+
return name, string(c), nil
2538+
}
2539+
25192540
func (config *configOptions) loadRoutingNamespaces() *configOptions {
25202541
for _, namespace := range config.RoutingNamespaces {
25212542
routingNamespaces[namespace] = true

0 commit comments

Comments
 (0)