add NilJournal; fix call sites to ChainStore constructor.
This commit is contained in:
@@ -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 }
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user