forked from raf181/Ghostkey_Server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcluster.go
More file actions
59 lines (48 loc) · 1.46 KB
/
cluster.go
File metadata and controls
59 lines (48 loc) · 1.46 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// cluster.go
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
// getClusterStatus returns information about the cluster status
func getClusterStatus(c *gin.Context) {
// Get active nodes
activeNodes := getActiveNodes()
// Check if cluster mode is enabled
clusterEnabled := config.ClusterEnabled
// Get other relevant information
response := gin.H{
"node_id": config.NodeID,
"cluster_enabled": clusterEnabled,
"nodes": activeNodes,
"node_count": len(activeNodes),
"status": "healthy",
"synchronized": true,
}
c.JSON(http.StatusOK, response)
}
// Update hook functions to publish entity changes when entities are created, updated, or deleted
// After registering a user, publish the change
func publishUserChange(user User, action string) {
if config.ClusterEnabled {
PublishEntityChange("user", action, user.ID, user)
}
}
// After registering a device, publish the change
func publishDeviceChange(device ESPDevice, action string) {
if config.ClusterEnabled {
PublishEntityChange("device", action, device.ID, device)
}
}
// After adding a command, publish the change
func publishCommandChange(command Command, action string) {
if config.ClusterEnabled {
PublishEntityChange("command", action, command.ID, command)
}
}
// After file operations, publish the change
func publishFileChange(file FileMetadata, action string) {
if config.ClusterEnabled {
PublishEntityChange("file", action, file.ID, file)
}
}