summary refs log tree commit diff stats
path: root/svc/help.go
Commit message (Expand)AuthorAgeFilesLines
* updated available intervals for cache/pushBen Morrison2019-06-081-1/+1
* help and manual text moved to help.goBen Morrison2019-06-061-0/+273
itle='author Ben Morrison <ben@gbmor.dev> 2019-06-04 18:14:24 -0400 committer Ben Morrison <ben@gbmor.dev> 2019-06-04 18:20:11 -0400 split caching and db function files' href='/gbmor/getwtxt/commit/db.go?h=v0.4.12&id=c8fddff33128555a68c6add0f6b457605b1ac121'>c8fddff ^
930ef34 ^
c8fddff ^

fdd9bd0 ^








e9d4a6b ^




fdd9bd0 ^

439695f ^

439695f ^
a5a32e7 ^


439695f ^


a5a32e7 ^
78f4d8a ^
439695f ^


78f4d8a ^
e9d4a6b ^
439695f ^
439695f ^
439695f ^
1a15258 ^
439695f ^

fdd9bd0 ^








c8fddff ^

fdd9bd0 ^

1a15258 ^
c8fddff ^
e9d4a6b ^
c8fddff ^

930ef34 ^

e9d4a6b ^
c8fddff ^

fdd9bd0 ^
1a15258 ^
c8fddff ^
c8fddff ^
e9d4a6b ^
c8fddff ^
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
                                                      

        
                                             
                               

 








                                                




                      

                                          

                     
                          


                                


                               
                                                         
                                 


                                      
                                 
 
         
 
                    
                

 








                                             

 

                                        
                     
                      
                        

                    

                   
                  

 
                                            
               
                      
                 
                    
 
package svc // import "github.com/getwtxt/getwtxt/svc"

import (
	"github.com/syndtr/goleveldb/leveldb"
	"golang.org/x/sys/unix"
)

// Everything in this file is database-agnostic.
// Functions and types related to specific kinds
// of databases will be in their own respective
// files, such as:
//  - leveldb.go
//  - sqlite.go

// Abstraction to allow several different
// databases to be used interchangeably.
type dbase interface {
	push() error
	pull()
}

// Opens a new connection to the specified
// database, then reads it into memory.
func initDatabase() {
	var db dbase
	confObj.Mu.RLock()
	dbpath := confObj.DBPath
	confObj.Mu.RUnlock()

	switch confObj.DBType {

	case "leveldb":
		lvl, err := leveldb.OpenFile(dbpath, nil)
		errFatal("", err)
		db = &dbLevel{db: lvl}

	case "sqlite":
		db = initSqlite()

	}

	dbChan <- db
	pullDB()
}

// Close the database connection.
func killDB() {
	db := <-dbChan
	switch dbType := db.(type) {
	case *dbLevel:
		errLog("", dbType.db.Close())
	case *dbSqlite:
		errLog("", dbType.db.Close())
	}
}

// Pushes the registry's cache data
// to a local database for safe keeping.
func pushDB() error {
	db := <-dbChan
	err := db.push()
	dbChan <- db

	unix.Sync()

	return err
}

// Reads the database from disk into memory.
func pullDB() {
	db := <-dbChan
	db.pull()
	dbChan <- db
}