Initial logic to support logging activity on Wings to send back to the panel
This commit is contained in:
38
database/database.go
Normal file
38
database/database.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"emperror.dev/errors"
|
||||
"github.com/apex/log"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/xujiajun/nutsdb"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var db *nutsdb.DB
|
||||
var syncer sync.Once
|
||||
|
||||
var (
|
||||
ServerEventsBucket = "server_events"
|
||||
)
|
||||
|
||||
func initialize() error {
|
||||
opt := nutsdb.DefaultOptions
|
||||
opt.Dir = filepath.Join(config.Get().System.RootDirectory, "db")
|
||||
|
||||
instance, err := nutsdb.Open(opt)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
db = instance
|
||||
return nil
|
||||
}
|
||||
|
||||
func DB() *nutsdb.DB {
|
||||
syncer.Do(func() {
|
||||
if err := initialize(); err != nil {
|
||||
log.WithField("error", err).Fatal("database: failed to initialize instance, this is an unrecoverable error")
|
||||
}
|
||||
})
|
||||
return db
|
||||
}
|
||||
Reference in New Issue
Block a user