-
Notifications
You must be signed in to change notification settings - Fork 1
/
clusterRoutes.go
42 lines (35 loc) · 942 Bytes
/
clusterRoutes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"github.com/gin-gonic/gin"
)
type ClusterNodesResponseNode struct {
LocalCluster string `json:"localCluster"`
IP string `json:"ip"`
Port int `json:"port"`
Status string `json:"status"`
Name string `json:"name"`
}
type ClusterNodesResponse struct {
Nodes []ClusterNodesResponseNode `json:"nodes"`
}
func HandleClusterRoutes(r *gin.Engine) {
clusterGroup := r.Group("/cluster")
clusterGroup.GET("/nodes", func(c *gin.Context) {
nodeList := make([]*ClusterNode, 0)
for _, v := range AllNodes {
nodeList = append(nodeList, v)
}
c.JSON(200, nodeList)
})
clusterGroup.POST("/addIndex", func(c *gin.Context) {
fmt.Println("Being told to add index")
data, _ := ioutil.ReadAll(c.Request.Body)
jDat := GossipMessageTypeAddIndex{}
json.Unmarshal([]byte(data), &jDat)
ClusterAddIndex(&jDat)
c.String(200, "Done")
})
}