Move audit subscribe to client, Fix tests
This commit is contained in:
10
main.go
10
main.go
@@ -94,6 +94,8 @@ type MongoClient struct {
|
||||
WithAudit bool
|
||||
// OnAudit callback called when audit is enabled.
|
||||
OnAudit *OnAudit
|
||||
// EventBus
|
||||
EventBus *events.TypedEventBus
|
||||
// IgnoreAudit a list of entities to ignore
|
||||
IgnoreAudit []string
|
||||
}
|
||||
@@ -364,11 +366,11 @@ func Start(props *MongoStartProps) error {
|
||||
|
||||
client.WithAudit = props.WithAudit
|
||||
|
||||
client.OnAudit = props.OnAudit
|
||||
client.EventBus = events.NewTypedEventBus()
|
||||
|
||||
if client.WithAudit {
|
||||
var onAudit OnAudit = func(audit *AuditResult) error {
|
||||
return events.Publish(audit)
|
||||
return events.Publish(client.EventBus, audit)
|
||||
}
|
||||
client.OnAudit = &onAudit
|
||||
}
|
||||
@@ -402,6 +404,10 @@ func Start(props *MongoStartProps) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *MongoClient) Subscribe(h events.Handler[AuditResult]) (cancel func()) {
|
||||
return events.Subscribe(c.EventBus, h)
|
||||
}
|
||||
|
||||
func GetClient() *mongo.Client {
|
||||
return client.Client
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user