mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 02:32:39 +01:00
db: Add very initial buntdb datastore
This commit is contained in:
parent
31757a64d7
commit
1746be2bb8
2
.gitignore
vendored
2
.gitignore
vendored
@ -93,7 +93,7 @@ _testmain.go
|
||||
|
||||
|
||||
### Oragono ###
|
||||
/ircd.*
|
||||
/ircd*
|
||||
/ssl.*
|
||||
/tls.*
|
||||
/oragono
|
||||
|
@ -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")
|
||||
|
@ -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 {
|
||||
|
@ -54,11 +54,11 @@ Options:
|
||||
fmt.Print("\n")
|
||||
fmt.Println(encoded)
|
||||
} else if arguments["initdb"].(bool) {
|
||||
irc.InitDB(config.Server.Database)
|
||||
log.Println("database initialized: ", config.Server.Database)
|
||||
irc.InitDB(config.Datastore.SQLitePath)
|
||||
log.Println("database initialized: ", config.Datastore.SQLitePath)
|
||||
} else if arguments["upgradedb"].(bool) {
|
||||
irc.UpgradeDB(config.Server.Database)
|
||||
log.Println("database upgraded: ", config.Server.Database)
|
||||
irc.UpgradeDB(config.Datastore.SQLitePath)
|
||||
log.Println("database upgraded: ", config.Datastore.SQLitePath)
|
||||
} else if arguments["mkcerts"].(bool) {
|
||||
log.Println("making self-signed certificates")
|
||||
|
||||
|
14
oragono.yaml
14
oragono.yaml
@ -5,14 +5,22 @@ network:
|
||||
# name of the network
|
||||
name: OragonoTest
|
||||
|
||||
# datastore configuration
|
||||
datastore:
|
||||
# path to the datastore
|
||||
# this can also be ":memory:" for an in-memory-only db
|
||||
path: ircd.db
|
||||
|
||||
# path to our sqlite db
|
||||
# currently used to lookup masks and store persistent chan data
|
||||
# but planned to be deprecated in a future release
|
||||
sqlite-path: ircd-sqlite.db
|
||||
|
||||
# server configuration
|
||||
server:
|
||||
# server name
|
||||
name: oragono.test
|
||||
|
||||
# database filename (sqlite db)
|
||||
database: ircd.db
|
||||
|
||||
# addresses to listen on
|
||||
listen:
|
||||
- ":6667"
|
||||
|
Loading…
Reference in New Issue
Block a user