2024-10-07 15:25:13 +05:30
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
2024-10-07 16:49:36 +05:30
|
|
|
"log"
|
2024-10-07 16:26:41 +05:30
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"elasticstream/config"
|
|
|
|
"elasticstream/source"
|
2024-10-07 15:25:13 +05:30
|
|
|
"elasticstream/source/elastic"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
var client *elastic.Client
|
|
|
|
|
|
|
|
func Open(c *gin.Context) {
|
2024-10-07 16:49:36 +05:30
|
|
|
log.Println(">>>> controller.Open()")
|
|
|
|
defer log.Println("<<<< controller.Open()")
|
2024-10-07 15:25:13 +05:30
|
|
|
|
|
|
|
client = elastic.NewClient()
|
|
|
|
|
2024-10-07 16:49:36 +05:30
|
|
|
err := client.Configure(c, &config.Config{
|
2024-10-07 15:25:13 +05:30
|
|
|
Host: "http://test.urantiacloud.com:9200",
|
|
|
|
Indexes: []string{"index-a", "index-b", "index-c"},
|
|
|
|
BatchSize: 100,
|
|
|
|
DBPath: "index.db",
|
|
|
|
})
|
|
|
|
if err != nil {
|
2024-10-07 22:41:59 +05:30
|
|
|
log.Println("client.Configure() err:", err)
|
2024-10-07 15:25:13 +05:30
|
|
|
c.Status(http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-10-07 16:26:41 +05:30
|
|
|
// get position from boltdb
|
|
|
|
var positions []source.Position
|
|
|
|
|
2024-10-07 16:49:36 +05:30
|
|
|
log.Printf("client: %#v\n", client)
|
|
|
|
|
2024-10-07 16:26:41 +05:30
|
|
|
err = client.Open(c, positions)
|
2024-10-07 15:25:13 +05:30
|
|
|
if err != nil {
|
|
|
|
c.Status(http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.Status(http.StatusOK)
|
|
|
|
}
|