wip: basic feat
This commit is contained in:
65
internal/es/client.go
Normal file
65
internal/es/client.go
Normal file
@ -0,0 +1,65 @@
|
||||
package es
|
||||
|
||||
import (
|
||||
"esgo2dump/internal/interfaces"
|
||||
"fmt"
|
||||
elastic "github.com/elastic/go-elasticsearch/v8"
|
||||
"github.com/elastic/go-elasticsearch/v8/esapi"
|
||||
"github.com/sirupsen/logrus"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func NewClient(url *url.URL) (interfaces.DumpIO, error) {
|
||||
|
||||
var (
|
||||
err error
|
||||
endpoint = fmt.Sprintf("%s://%s:%s", url.Scheme, url.Host, url.Port())
|
||||
c *elastic.Client
|
||||
infoResp *esapi.Response
|
||||
)
|
||||
|
||||
logrus.Debugf("es.NewClient: endpoint=%s", endpoint)
|
||||
|
||||
if c, err = elastic.NewClient(
|
||||
elastic.Config{
|
||||
Addresses: []string{endpoint},
|
||||
Username: "",
|
||||
Password: "",
|
||||
CACert: nil,
|
||||
RetryOnStatus: []int{429},
|
||||
MaxRetries: 3,
|
||||
RetryBackoff: nil,
|
||||
},
|
||||
); err != nil {
|
||||
logrus.Debugf("es.NewClient: elastic new client with endpont=%s err=%v", endpoint, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if infoResp, err = c.Info(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if infoResp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("info es status=%d", infoResp.StatusCode)
|
||||
}
|
||||
|
||||
return &client{c: c}, nil
|
||||
}
|
||||
|
||||
type client struct {
|
||||
c *elastic.Client
|
||||
}
|
||||
|
||||
func (c *client) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c client) Write(docs []map[string]any) (int, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (c client) Read(i int) ([]map[string]any, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
Reference in New Issue
Block a user