logmania/database/read.go

27 lines
453 B
Go
Raw Permalink 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 {
log.Infof("loaded %d hosts", len(db.HostTo))
db.InitNotify()
db.InitHost()
// import
db.update()
return &db
} else {
log.Error("failed to open db file: ", path, ":", err)
}
adb := &DB{}
adb.InitNotify()
adb.InitHost()
return adb
}