-
Notifications
You must be signed in to change notification settings - Fork 2
/
module.go
55 lines (43 loc) · 946 Bytes
/
module.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
52
53
54
55
package redis
import (
"context"
e "github.com/americanas-go/ignite/elastic/go-elasticsearch.v8"
"github.com/elastic/go-elasticsearch/v8"
"sync"
contextfx "github.com/americanas-go/ignite/go.uber.org/fx.v1/module/context"
"go.uber.org/fx"
)
var once sync.Once
type clientParams struct {
fx.In
Plugins []e.Plugin `optional:"true"`
}
// Module fx module for elasticsearch client.
func Module() fx.Option {
options := fx.Options()
once.Do(func() {
options = fx.Options(
contextfx.Module(),
fx.Provide(
func(ctx context.Context, p clientParams) (*elasticsearch.Client, error) {
return e.NewClient(ctx, p.Plugins...)
},
),
)
})
return options
}
var bonce sync.Once
// BulkModule fx module for elasticsearch bulk indexer.
func BulkModule() fx.Option {
options := fx.Options()
bonce.Do(func() {
options = fx.Options(
Module(),
fx.Provide(
e.NewBulkIndexer,
),
)
})
return options
}