elasticstream/controller/open.go

35 lines
643 B
Go
Raw Normal View History

2024-10-07 15:25:13 +05:30
package controller
import (
"elasticstream/source/elastic"
"github.com/elastic/go-elasticsearch/v8"
"github.com/gin-gonic/gin"
)
var client *elastic.Client
func Open(c *gin.Context) {
client = elastic.NewClient()
err := client.Configure(&Config{
Host: "http://test.urantiacloud.com:9200",
Indexes: []string{"index-a", "index-b", "index-c"},
BatchSize: 100,
DBPath: "index.db",
})
if err != nil {
c.Status(http.StatusInternalServerError)
return
}
// Open connection with Elastic Search
err = client.Open()
if err != nil {
c.Status(http.StatusInternalServerError)
return
}
c.Status(http.StatusOK)
}