Add AutoCleanup in configuration

This commit is contained in:
George Suntres
2026-04-27 13:54:51 -04:00
parent 40ce8d334b
commit 1142585f84

View File

@@ -315,6 +315,7 @@ type MongoStartProps struct {
MongoDBPrefix string MongoDBPrefix string
ContextFields []string ContextFields []string
WithAudit bool WithAudit bool
AutoCleanup bool
OnAudit *OnAudit OnAudit *OnAudit
AllowTruncatingDoubles bool AllowTruncatingDoubles bool
} }
@@ -410,11 +411,13 @@ func Start(props *MongoStartProps) error {
return err return err
} }
if props.AutoCleanup {
sys.OnExit(func () { sys.OnExit(func () {
if err := client.Client.Disconnect(context.TODO()); err != nil { if err := Stop(); err != nil {
log.Fatalf("failed to disconnect: %v", err) log.Fatalf("failed to disconnect: %v", err)
} }
}) })
}
// Register defaults.go // Register defaults.go
var structfulDef bson.M var structfulDef bson.M