diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-06-06 16:07:53 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-06-08 02:29:20 -0400 |
commit | e9d4a6b0e8624c6425d467f0efe14be1bc683bd9 (patch) | |
tree | 02b928c2c8fe28153980e6612c3349104091c083 /svc/db.go | |
parent | 6749dc4d215dd60900f0c1187ba20031ccdc4f85 (diff) | |
download | getwtxt-e9d4a6b0e8624c6425d467f0efe14be1bc683bd9.tar.gz |
database refs and static assets concurrency-safe
Diffstat (limited to 'svc/db.go')
-rw-r--r-- | svc/db.go | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/svc/db.go b/svc/db.go index 0bb96ee..e0c2690 100644 --- a/svc/db.go +++ b/svc/db.go @@ -11,6 +11,11 @@ import ( "github.com/syndtr/goleveldb/leveldb" ) +type dbase interface { + push() error + pull() +} + type dbLevel struct { db *leveldb.DB } @@ -19,9 +24,8 @@ type dbSqlite struct { db *sql.DB } -type dbase interface { - push() error - pull() +type dbPostgres struct { + db *sql.DB } // Pull DB data into cache, if available. @@ -41,6 +45,10 @@ func initDatabase() { var lite *sql.DB db = &dbSqlite{db: lite} + case "postgres": + var pg *sql.DB + db = &dbPostgres{db: pg} + } confObj.Mu.RUnlock() @@ -65,15 +73,16 @@ func dbTimer() bool { // database for safe keeping. func pushDB() error { db := <-dbChan + err := db.push() dbChan <- db - return db.push() + return err } func pullDB() { db := <-dbChan - dbChan <- db db.pull() + dbChan <- db } func (lvl dbLevel) push() error { @@ -176,3 +185,12 @@ func (lite dbSqlite) push() error { func (lite dbSqlite) pull() { } + +func (pg dbPostgres) push() error { + + return nil +} + +func (pg dbPostgres) pull() { + +} |