diff options
author | Georg Pfuetzenreuter | 2024-10-10 00:04:16 +0200 |
---|---|---|
committer | Georg Pfuetzenreuter | 2024-10-10 00:04:16 +0200 |
commit | dfe7deff72ec77f798efe243c1c22bb63c523040 (patch) | |
tree | 2e6a75f85583b04a7a19c54fade8e5ddb7cc44e6 /wat | |
parent | e300f7137055a260c522fe546a75e528533cf812 (diff) | |
download | watbot-dfe7deff72ec77f798efe243c1c22bb63c523040.tar.gz watbot-dfe7deff72ec77f798efe243c1c22bb63c523040.tar.bz2 watbot-dfe7deff72ec77f798efe243c1c22bb63c523040.zip |
Configurable database path
Allow the database file to reside in a user defined location instead of
requiring it to be in the working directory.
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
Diffstat (limited to 'wat')
-rw-r--r-- | wat/bot.go | 3 | ||||
-rw-r--r-- | wat/db.go | 4 |
2 files changed, 4 insertions, 3 deletions
@@ -20,6 +20,7 @@ type WatBot struct { } type WatConfig struct { + DatabasePath string BotHosts []string BotGames BotGameConfig AdminHosts []string @@ -30,7 +31,7 @@ type WatConfig struct { func NewWatBot(config *irc.ClientConfig, watConfig *WatConfig, serverConn *tls.Conn) *WatBot { wat := WatBot{conn: serverConn, Nick: config.Nick, c: watConfig} - wat.Db = NewWatDb() + wat.Db = NewWatDb(watConfig.DatabasePath) wat.game = NewWatGame(&wat, wat.Db) wat.integration = NewWatIntegration(&wat, wat.Db, &WatIntegrationConfig{BotHosts: watConfig.BotHosts, BotGames: watConfig.BotGames}) config.Handler = irc.HandlerFunc(wat.HandleIrcMsg) @@ -52,10 +52,10 @@ type WatDb struct { db *gorm.DB } -func NewWatDb() *WatDb { +func NewWatDb(dbpath string) *WatDb { w := WatDb{} var err error - w.db, err = gorm.Open(sqlite.Open("wat.db"), &gorm.Config{}) + w.db, err = gorm.Open(sqlite.Open(dbpath), &gorm.Config{}) if err != nil { panic(err) } |