-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Daksh Chauhan <dak-x@outlook.com>
- Loading branch information
Showing
3 changed files
with
72 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package elastic | ||
|
||
import ( | ||
"log" | ||
"time" | ||
|
||
"github.com/elastic/go-elasticsearch/v7" | ||
) | ||
|
||
var client *elasticsearch.Client | ||
|
||
func init() { | ||
|
||
esCfg := elasticsearch.Config{ | ||
Addresses: []string{ | ||
"http://elastic:9200/", | ||
}, | ||
} | ||
|
||
client, err := elasticsearch.NewClient(esCfg) | ||
|
||
if err != nil { | ||
log.Fatalf("Cannot create Client: %v", err) | ||
} | ||
|
||
esInfo, err := client.Info() | ||
|
||
var numRetries int = 0 | ||
|
||
for err != nil { | ||
// Wait for the instane to get up and running. | ||
time.Sleep(3 * time.Second) | ||
numRetries++ | ||
if numRetries == 5 { | ||
break | ||
} | ||
esInfo, err = client.Info() | ||
} | ||
|
||
if err != nil { | ||
log.Fatalf("Elastic is not running %s", err) | ||
} | ||
|
||
log.Printf("ELASTIC IS UP: %v\n", esInfo) | ||
log.Printf("STARTING SOKEMOTOR SERVICE \n") | ||
|
||
} | ||
|
||
func GetEsClint() *elasticsearch.Client { | ||
return client | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ go 1.16 | |
require github.com/gin-gonic/gin v1.7.2 | ||
|
||
require github.com/elastic/go-elasticsearch/v7 v7.13.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters