From 439695f5521924833153852dc84040554e835f11 Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Thu, 6 Jun 2019 01:23:44 -0400 Subject: moved initDatabase() to db.go --- svc/db.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'svc/db.go') 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 -- cgit 1.4.1-2-gfad0 about summary refs log tree commit diff stats
path: root/Makefile.am
blob: a5bf1240180c904147264ea14625470216dbfa05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23