Allow to override database path through DIUN_DB env var

This commit is contained in:
CrazyMax
2019-08-22 21:19:24 +02:00
parent 99efeccf0b
commit 3013512af6
2 changed files with 12 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ import (
"regexp"
"github.com/crazy-max/diun/internal/model"
"github.com/crazy-max/diun/internal/utl"
"github.com/imdario/mergo"
"github.com/rs/zerolog/log"
"gopkg.in/yaml.v2"
@@ -88,6 +89,7 @@ func (cfg *Config) validate() error {
cfg.Db.Path = "/data/diun.db"
}
cfg.Db.Path = utl.GetEnv("DIUN_DB", cfg.Db.Path)
if cfg.Db.Path == "" {
return errors.New("database path is required")
}

View File

@@ -1,6 +1,7 @@
package utl
import (
"os"
"regexp"
)
@@ -41,3 +42,12 @@ func IsExcluded(s string, excludes []string) bool {
}
return false
}
// GetEnv retrieves the value of the environment variable named by the key
// or fallback if not found
func GetEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}