logmania/database/read.go

27 lines
486 B
Go
Raw Normal View History

2018-04-15 01:52:08 +02:00
package database
import (
"dev.sum7.eu/genofire/golang-lib/file"
log "github.com/sirupsen/logrus"
)
func ReadDBFile(path string) *DB {
var db DB
if err := file.ReadJSON(path, &db); err == nil {
db.InitNotify()
db.InitHost()
// import
db.update()
2018-05-18 14:04:54 +02:00
log.Infof("loaded %d hosts and %d notifies", len(db.Hosts), len(db.Notifies))
2018-04-15 01:52:08 +02:00
return &db
} else {
log.Error("failed to open db file: ", path, ":", err)
}
adb := &DB{}
adb.InitNotify()
adb.InitHost()
return adb
}