Add AutoCleanup in configuration
This commit is contained in:
5
main.go
5
main.go
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user