Skip to content

Commit

Permalink
Add elasticsearch v8
Browse files Browse the repository at this point in the history
  • Loading branch information
minhduc140583 committed Jul 30, 2023
1 parent 7e5e967 commit 3981754
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions elasticsearch/v8/health_checker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package elasticsearch

import (
"context"
"github.com/elastic/go-elasticsearch/v8"
)

type HealthChecker struct {
client *elasticsearch.Client
name string
}

func NewHealthChecker(client *elasticsearch.Client, options ...string) *HealthChecker {
var name string
if len(options) > 0 && len(options[0]) > 0 {
name = options[0]
} else {
name = "elasticsearch"
}
return &HealthChecker{client, name}
}

func (e *HealthChecker) Name() string {
return e.name
}

func (e *HealthChecker) Check(ctx context.Context) (map[string]interface{}, error) {
res := make(map[string]interface{})
_, err := e.client.Ping()
if err != nil {
return res, err
}
return res, nil
}

func (e *HealthChecker) Build(ctx context.Context, data map[string]interface{}, err error) map[string]interface{} {
if err == nil {
return data
}
if data == nil {
data = make(map[string]interface{}, 0)
}
data["error"] = err.Error()
return data
}

0 comments on commit 3981754

Please sign in to comment.