elasticstream/client.go

51 lines
775 B
Go
Raw Normal View History

2024-10-03 12:40:46 +05:30
package elasticstream
import (
"github.com/elastic/go-elasticsearch/v8"
)
type Client struct {
es *elasticsearch.Client
config *Config
}
2024-10-03 12:57:23 +05:30
func NewClient(config *Config) (*Client, error) {
client := &Client{
config: config,
}
cfg := elasticsearch.Config{
Addresses: []string{
config.Host,
},
}
es, err := elasticsearch.NewClient(cfg)
2024-10-03 12:40:46 +05:30
if err != nil {
return nil, err
}
2024-10-03 12:57:23 +05:30
client.es = es
return client, nil
2024-10-03 12:40:46 +05:30
}
func (c *Client) Open() error {
// create a buffer channel
ch := make(chan Data, 1)
for index, from := range c.config.Indexes {
NewWorker(c.es, index, from, c.config.BatchSize, ch)
}
return nil
}
func (c *Client) Read() (Data, error) {
return Data{}, nil
}
// close the client
func (c *Client) Teardown() error {
return nil
}