diff options
Diffstat (limited to 'svc')
-rw-r--r-- | svc/db.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/svc/db.go b/svc/db.go index 8c3f278..10ea28d 100644 --- a/svc/db.go +++ b/svc/db.go @@ -1,6 +1,7 @@ package svc // import "github.com/getwtxt/getwtxt/svc" import ( + "database/sql" "log" "net" "strings" @@ -10,6 +11,35 @@ import ( "github.com/syndtr/goleveldb/leveldb" ) +// Pull DB data into cache, if available. +func initDatabase() { + var db dbase + var err error + + confObj.Mu.RLock() + switch confObj.DBType { + + case "leveldb": + var lvl *leveldb.DB + lvl, err = leveldb.OpenFile(confObj.DBPath, nil) + db = &dbLevel{db: lvl} + + case "sqlite": + var lite *sql.DB + db = &dbSqlite{db: lite} + + } + confObj.Mu.RUnlock() + + if err != nil { + log.Fatalf("%v\n", err.Error()) + } + + dbChan <- db + + pullDatabase() +} + func checkDBtime() bool { confObj.Mu.RLock() answer := time.Since(confObj.LastPush) > confObj.DBInterval |