logmania/database/read.go

27 lines
475 B
Go
Raw Normal View History

2018-04-15 01:52:08 +02:00
package database
import (
"dev.sum7.eu/genofire/golang-lib/file"
2019-06-20 09:25:43 +02:00
"github.com/bdlm/log"
2018-04-15 01:52:08 +02:00
)
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
}