-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
45 lines (40 loc) · 1.06 KB
/
client.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
package mongoleaf
import (
"context"
"go.mongodb.org/mongo-driver/mongo/readpref"
)
func (branch Branch) Connect() error {
return branch.Client.Connect(context.TODO())
}
func (branch Branch) Disconnect() error {
return branch.Client.Disconnect(context.TODO())
}
func (branch Branch) ListDatabaseNames(filter, optionQuery string) ([]string, error) {
filterMap, err := jsonToMap(filter)
if err != nil {
return nil, err
}
op, err := option.listDatabase(optionQuery)
if err != nil {
return nil, err
}
return branch.Client.ListDatabaseNames(context.TODO(), filterMap, &op)
}
func (branch Branch) ListDatabases(filter, optionQuery string) (map[string]interface{}, error) {
filterMap, err := jsonToMap(filter)
if err != nil {
return nil, err
}
op, err := option.listDatabase(optionQuery)
if err != nil {
return nil, err
}
res, err := branch.Client.ListDatabases(context.TODO(), filterMap, &op)
if err != nil {
return nil, err
}
return structToMap(res)
}
func (branch Branch) Ping() error {
return branch.Client.Ping(context.TODO(), readpref.Primary())
}