Add AutoCleanup in configuration

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

13
main.go
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
} }
sys.OnExit(func () { if props.AutoCleanup {
if err := client.Client.Disconnect(context.TODO()); err != nil { sys.OnExit(func () {
log.Fatalf("failed to disconnect: %v", err) if err := Stop(); err != nil {
} log.Fatalf("failed to disconnect: %v", err)
}) }
})
}
// Register defaults.go // Register defaults.go
var structfulDef bson.M var structfulDef bson.M