-
Notifications
You must be signed in to change notification settings - Fork 0
/
with.go
51 lines (43 loc) · 1.24 KB
/
with.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package dockerdb
import "context"
func With(ctx context.Context, c Config, fn func(c Config, vdb *VDB) error) (err error) {
vdb, err := New(ctx, c)
if err != nil {
if vdb != nil {
err := vdb.Clear(ctx)
if err != nil {
return err
}
}
return err
}
defer func() { err = vdb.Clear(ctx) }()
return fn(c, vdb)
}
func WithPostgres(ctx context.Context, name string, fn func(c Config, vdb *VDB) error) (err error) {
return With(ctx, PostgresConfig(name).Build(), fn)
}
func WithMySQL(ctx context.Context, name string, fn func(c Config, vdb *VDB) error) (err error) {
return With(ctx, MySQLConfig(name).Build(), fn)
}
func WithRedis(
ctx context.Context, name string,
checkWakeUp func(c Config) (stop bool),
fn func(c Config, vdb *VDB) error,
) (err error) {
return With(ctx, RedisConfig(name, checkWakeUp).Build(), fn)
}
func WithKeyDB(
ctx context.Context, name string,
checkWakeUp func(c Config) (stop bool),
fn func(c Config, vdb *VDB) error,
) (err error) {
return With(ctx, KeyDBConfig(name, checkWakeUp).Build(), fn)
}
func WithScyllaDB(
ctx context.Context, name string,
checkWakeUp func(c Config) (stop bool),
fn func(c Config, vdb *VDB) error,
) (err error) {
return With(ctx, ScyllaDBConfig(name, checkWakeUp).Build(), fn)
}