forked from gdgtoledo/linneo
-
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.
[gdgtoledo#7] split elasticsearch into diferent files
- Loading branch information
1 parent
645ed68
commit 97c783d
Showing
2 changed files
with
44 additions
and
39 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,36 @@ | ||
package elastic | ||
|
||
import ( | ||
es "github.com/elastic/go-elasticsearch/v8" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var esInstance *es.Client | ||
|
||
// GetClient returns a client connected to the running elasticseach cluster | ||
func GetClient() (*es.Client, error) { | ||
if esInstance != nil { | ||
return esInstance, nil | ||
} | ||
|
||
cfg := es.Config{ | ||
Addresses: []string{ | ||
"http://elasticsearch:9200", | ||
"http://elasticsearch2:9200", | ||
"http://elasticsearch3:9200", | ||
}, | ||
} | ||
esClient, err := es.NewClient(cfg) | ||
if err != nil { | ||
log.WithFields(log.Fields{ | ||
"config": cfg, | ||
"error": err, | ||
}).Error("Could not obtain an Elasticsearch client") | ||
|
||
return nil, err | ||
} | ||
|
||
esInstance = esClient | ||
|
||
return esInstance, nil | ||
} |
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