mirror of
https://github.com/jeremyd/ergo.git
synced 2026-07-01 14:28:56 -07:00
db: Add very initial buntdb datastore
This commit is contained in:
+10
-3
@@ -49,11 +49,15 @@ type Config struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
Datastore struct {
|
||||
Path string
|
||||
SQLitePath string `yaml:"sqlite-path"`
|
||||
}
|
||||
|
||||
Server struct {
|
||||
PassConfig
|
||||
Password string
|
||||
Name string
|
||||
Database string
|
||||
Listen []string
|
||||
Wslisten string `yaml:"ws-listen"`
|
||||
TLSListeners map[string]*TLSListenConfig `yaml:"tls-listeners"`
|
||||
@@ -131,8 +135,11 @@ func LoadConfig(filename string) (config *Config, err error) {
|
||||
if !IsHostname(config.Server.Name) {
|
||||
return nil, errors.New("Server name must match the format of a hostname")
|
||||
}
|
||||
if config.Server.Database == "" {
|
||||
return nil, errors.New("Server database missing")
|
||||
if config.Datastore.Path == "" {
|
||||
return nil, errors.New("Datastore path missing")
|
||||
}
|
||||
if config.Datastore.SQLitePath == "" {
|
||||
return nil, errors.New("SQLite database path missing")
|
||||
}
|
||||
if len(config.Server.Listen) == 0 {
|
||||
return nil, errors.New("Server listening addresses missing")
|
||||
|
||||
+11
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user