mirror of
https://github.com/mjl-/mox.git
synced 2024-12-26 16:33:47 +03:00
ec967ef321
the stuttering was introduced to make the same type name declared in multiple packages, and used in the admin sherpa api, unique. with sherpadoc's new rename, we can make them unique when generating the api definition/docs, and the Go code can use nicer names.
49 lines
912 B
Go
49 lines
912 B
Go
package tlsrptdb
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/mjl-/bstore"
|
|
|
|
"github.com/mjl-/mox/mlog"
|
|
"github.com/mjl-/mox/mox-"
|
|
)
|
|
|
|
var (
|
|
ReportDBTypes = []any{Record{}}
|
|
ReportDB *bstore.DB
|
|
mutex sync.Mutex
|
|
|
|
// Accessed directly by tlsrptsend.
|
|
ResultDBTypes = []any{TLSResult{}, SuppressAddress{}}
|
|
ResultDB *bstore.DB
|
|
)
|
|
|
|
// Init opens and possibly initializes the databases.
|
|
func Init() error {
|
|
if _, err := reportDB(mox.Shutdown); err != nil {
|
|
return err
|
|
}
|
|
if _, err := resultDB(mox.Shutdown); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Close closes the database connections.
|
|
func Close() {
|
|
log := mlog.New("tlsrptdb", nil)
|
|
if ResultDB != nil {
|
|
err := ResultDB.Close()
|
|
log.Check(err, "closing result database")
|
|
ResultDB = nil
|
|
}
|
|
|
|
mutex.Lock()
|
|
defer mutex.Unlock()
|
|
if ReportDB != nil {
|
|
err := ReportDB.Close()
|
|
log.Check(err, "closing report database")
|
|
ReportDB = nil
|
|
}
|
|
}
|