-
Notifications
You must be signed in to change notification settings - Fork 2
/
managed_client.go
49 lines (39 loc) · 1.21 KB
/
managed_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
46
47
48
49
package elasticsearch
import (
"context"
"github.com/elastic/go-elasticsearch/v7"
)
// ManagedClient struct that represents a managed client.
type ManagedClient struct {
Client *elasticsearch.Client
Plugins []Plugin
Options *Options
}
// NewManagedClientWithConfigPath returns a managed client with options from config path.
func NewManagedClientWithConfigPath(ctx context.Context, path string, plugins ...Plugin) (*ManagedClient, error) {
opts, err := NewOptionsWithPath(path)
if err != nil {
return nil, err
}
return NewManagedClientWithOptions(ctx, opts, plugins...)
}
// NewManagedClient returns a managed client with default options.
func NewManagedClient(ctx context.Context, plugins ...Plugin) (*ManagedClient, error) {
opts, err := NewOptions()
if err != nil {
return nil, err
}
return NewManagedClientWithOptions(ctx, opts, plugins...)
}
// NewManagedClientWithOptions returns a managed client with options.
func NewManagedClientWithOptions(ctx context.Context, opts *Options, plugins ...Plugin) (*ManagedClient, error) {
s, err := NewClientWithOptions(ctx, opts, plugins...)
if err != nil {
return nil, err
}
return &ManagedClient{
Client: s,
Plugins: plugins,
Options: opts,
}, nil
}