Skip to content

Commit

Permalink
fix warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Quang nd committed Aug 29, 2024
1 parent f1483e2 commit 68f3c51
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"strings"

"github.com/elastic/go-elasticsearch/v8"
"github.com/elastic/go-elasticsearch/v8/esapi"
"github.com/gin-gonic/gin"
"github.com/hashicorp/consul/api"
)
Expand All @@ -30,11 +29,10 @@ func readConsulConfig() string {
if pair == nil {
fmt.Println("Key 'SignalR.API/appsettings.Development.json' not found")
}

strVal := string(pair.Value)
if err != nil {
if pair != nil {
log.Fatalf("Consul value is nil: %s", err)
}
strVal := string(pair.Value)

var result map[string]interface{}
readJsonErr := json.Unmarshal([]byte(strVal), &result)
Expand Down Expand Up @@ -75,25 +73,25 @@ func connectElasticSearch(host string) *elasticsearch.Client {
return es
}

func validateIndexSearch(es *elasticsearch.Client) {
indexName := "cls-feature"
req := esapi.IndicesExistsRequest{
Index: []string{indexName},
}
res, err := req.Do(context.Background(), es)
if err != nil {
log.Fatalf("Error checking if the index exists: %s", err)
}
defer res.Body.Close()

if res.StatusCode == 200 {
return
} else if res.StatusCode == 404 {
es.Indices.Create("cls-feature")
} else {
log.Fatalf("Error checking if the index exists: %s", err)
}
}
// func validateIndexSearch(es *elasticsearch.Client) {
// indexName := "cls-feature"
// req := esapi.IndicesExistsRequest{
// Index: []string{indexName},
// }
// res, err := req.Do(context.Background(), es)
// if err != nil {
// log.Fatalf("Error checking if the index exists: %s", err)
// }
// defer res.Body.Close()

// if res.StatusCode == 200 {
// return
// } else if res.StatusCode == 404 {
// es.Indices.Create("cls-feature")
// } else {
// log.Fatalf("Error checking if the index exists: %s", err)
// }
// }

func insertSearch(es *elasticsearch.Client) gin.HandlerFunc {
return func(c *gin.Context) {
Expand Down

0 comments on commit 68f3c51

Please sign in to comment.