Allow the config file to be specified in the .env file.
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Captain ALM 2022-07-14 22:00:10 +01:00
parent 976d356398
commit 3910d29fa2
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1

View File

@ -10,6 +10,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"path" "path"
"path/filepath"
"sync" "sync"
"syscall" "syscall"
"time" "time"
@ -48,8 +49,18 @@ func main() {
check(os.MkdirAll(dataDir, 0777)) check(os.MkdirAll(dataDir, 0777))
//Config file processing:
configLocation := os.Getenv("CONFIG_FILE")
if configLocation == "" {
configLocation = path.Join(dataDir, "config.yml")
} else {
if !filepath.IsAbs(configLocation) {
configLocation = path.Join(dataDir, configLocation)
}
}
//Config loading: //Config loading:
configFile, err := os.Open(path.Join(dataDir, "config.yml")) configFile, err := os.Open(configLocation)
if err != nil { if err != nil {
log.Fatalln("Failed to open config.yml") log.Fatalln("Failed to open config.yml")
} }