Make DB path configurable

This commit is contained in:
Kenneth Bruen 2023-12-26 05:18:45 +01:00
parent 97e6d78ce6
commit 69a0cf3a01
Signed by: kbruen
GPG key ID: C1980A470C3EE5B1

View file

@ -59,7 +59,13 @@ func main() {
log.Fatal("ERROR: No bot token supplied; supply with CFR_BOT.TOKEN") log.Fatal("ERROR: No bot token supplied; supply with CFR_BOT.TOKEN")
} }
db, err := gorm.Open(sqlite.Open("bot_db.sqlite"), &gorm.Config{}) dbPath := os.Getenv("CFR_BOT.DB_PATH")
dbPath = strings.TrimSpace(dbPath)
if len(dbPath) == 0 {
dbPath = "bot_db.sqlite"
}
log.Printf("INFO : DB Path: %s\n", dbPath)
db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
if err != nil { if err != nil {
panic(err) panic(err)
} }