-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es.go
41 lines (36 loc) · 807 Bytes
/
es.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
package config
import (
"crypto/tls"
"fmt"
"net"
"net/http"
"os"
"time"
"github.com/elastic/go-elasticsearch/v8"
)
type ES struct {
*elasticsearch.Client
}
func newESClient() (*ES, error) {
connStr := fmt.Sprintf("%s:%s", os.Getenv("ES_HOST"), os.Getenv("ES_PORT"))
cfg := elasticsearch.Config{
Addresses: []string{connStr},
Username: os.Getenv("ES_USER"),
Password: os.Getenv("ES_PASS"),
Transport: &http.Transport{
MaxIdleConnsPerHost: 10,
ResponseHeaderTimeout: time.Millisecond,
DialContext: (&net.Dialer{Timeout: time.Nanosecond}).DialContext,
TLSClientConfig: &tls.Config{
MinVersion: tls.VersionTLS12,
// ...
},
},
}
client, err := elasticsearch.NewClient(cfg)
if err != nil {
return nil, err
}
es := &ES{client}
return es, nil
}