mirror of
https://github.com/mjl-/mox.git
synced 2024-12-27 08:53:48 +03:00
5b20cba50a
we don't want external software to include internal details like mlog. slog.Logger is/will be the standard. we still have mlog for its helper functions, and its handler that logs in concise logfmt used by mox. packages that are not meant for reuse still pass around mlog.Log for convenience. we use golang.org/x/exp/slog because we also support the previous Go toolchain version. with the next Go release, we'll switch to the builtin slog.
49 lines
927 B
Go
49 lines
927 B
Go
package tlsrptdb
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/mjl-/bstore"
|
|
|
|
"github.com/mjl-/mox/mlog"
|
|
"github.com/mjl-/mox/mox-"
|
|
)
|
|
|
|
var (
|
|
ReportDBTypes = []any{TLSReportRecord{}}
|
|
ReportDB *bstore.DB
|
|
mutex sync.Mutex
|
|
|
|
// Accessed directly by tlsrptsend.
|
|
ResultDBTypes = []any{TLSResult{}, TLSRPTSuppressAddress{}}
|
|
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
|
|
}
|
|
}
|