add NilJournal; fix call sites to ChainStore constructor.

This commit is contained in:
Raúl Kripalani
2020-07-17 19:10:47 +01:00
parent 4bcf01938c
commit becbff0b13
9 changed files with 37 additions and 8 deletions
+16
View File
@@ -0,0 +1,16 @@
package journal
type nilJournal struct{}
// nilj is a singleton nil journal.
var nilj Journal = &nilJournal{}
func NilJournal() Journal {
return nilj
}
func (n *nilJournal) RegisterEventType(_, _ string) EventType { return EventType{} }
func (n *nilJournal) AddEntry(_ EventType, _ interface{}) {}
func (n *nilJournal) Close() error { return nil }
+6
View File
@@ -3,7 +3,13 @@ package journal
// MaybeAddEntry is a convenience function that evaluates if the EventType is
// enabled, and if so, it calls the supplier to create the entry and
// subsequently journal.AddEntry on the provided journal to record it.
//
// This is safe to call with a nil Journal, either because the value is nil,
// or because a journal obtained through NilJournal() is in use.
func MaybeAddEntry(journal Journal, evtType EventType, supplier func() interface{}) {
if journal == nil || journal == nilj {
return
}
if !evtType.Enabled() {
return
}