-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
35 lines (30 loc) · 790 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package orm
import (
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/phntom/nixeepass/config"
"github.com/rs/zerolog/log"
)
type ormConfig struct {
Type string `mapstructure:"type"`
Sqlite3 ormConfigSqlite3 `mapstructure:"sqlite3"`
}
type ormConfigSqlite3 struct {
Filename string `mapstructure:"filename"`
PreparedStatement bool `mapstructure:"prepared_statement"`
}
var cfg ormConfig
func reloadConfig(in fsnotify.Event) {
log.Debug().Msg("Reloading orm configs")
err := config.Config().UnmarshalKey("db", &cfg)
if err != nil {
log.Info().Err(err).Msg("failed to reload db config")
}
if cfg.Type == "" {
cfg.Type = "sqlite3"
}
if cfg.Sqlite3.Filename == "" {
cfg.Sqlite3.Filename = fmt.Sprintf("%s.db", config.AppName)
}
reconnect()
}