-
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.
- add suport to elastic db
- Loading branch information
Showing
9 changed files
with
400 additions
and
31 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
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
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
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
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
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,38 @@ | ||
package elastic | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/elastic/go-elasticsearch/v8" | ||
) | ||
|
||
// Connect establishes a connection to the ElasticSearch cluster. | ||
// | ||
// It reads the ElasticSearch URI from the environment variable `ELASTIC_URI`. | ||
// | ||
// Returns: | ||
// - A pointer to an elasticsearch.Client instance. | ||
// - An error, if the connection fails. | ||
func Connect() (*elasticsearch.Client, error) { | ||
cfg := elasticsearch.Config{ | ||
Addresses: []string{ | ||
os.Getenv("ELASTIC_URI"), | ||
}, | ||
} | ||
|
||
client, err := elasticsearch.NewClient(cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Test connection | ||
res, err := client.Info() | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer res.Body.Close() | ||
|
||
log.Println("ElasticSearch connection established") | ||
return client, nil | ||
} |
Oops, something went wrong.