mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-25 23:03:58 +01:00
Allow to override database path through DIUN_DB env var
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user