db: Add very initial buntdb datastore

This commit is contained in:
Daniel Oaks
2016-08-19 23:21:52 +10:00
parent 31757a64d7
commit 1746be2bb8
5 changed files with 37 additions and 12 deletions
+11 -1
View File
@@ -22,6 +22,7 @@ import (
"time"
"github.com/DanielOaks/girc-go/ircmsg"
"github.com/tidwall/buntdb"
)
type Server struct {
@@ -30,6 +31,7 @@ type Server struct {
commands chan Command
ctime time.Time
db *sql.DB
store buntdb.DB
idle chan *Client
motdLines []string
name Name
@@ -65,7 +67,7 @@ func NewServer(config *Config) *Server {
clients: NewClientLookupSet(),
commands: make(chan Command),
ctime: time.Now(),
db: OpenDB(config.Server.Database),
db: OpenDB(config.Datastore.SQLitePath),
idle: make(chan *Client),
name: NewName(config.Server.Name),
nameString: NewName(config.Server.Name).String(),
@@ -78,6 +80,14 @@ func NewServer(config *Config) *Server {
checkIdent: config.Server.CheckIdent,
}
// open data store
db, err := buntdb.Open(config.Datastore.Path)
if err != nil {
log.Fatal(fmt.Sprintf("Failed to open datastore: %s", err.Error()))
}
defer db.Close()
server.store = *db
if config.Server.MOTD != "" {
file, err := os.Open(config.Server.MOTD)
if err == nil {