feat: introduce cluster agent

This commit is contained in:
2025-05-13 21:59:44 +02:00
parent ee0489dcbb
commit 49014c951f
12 changed files with 485 additions and 18 deletions

View File

@@ -6,6 +6,7 @@ import (
"log"
"net/http"
"github.com/0x1d/rcond/pkg/cluster"
network "github.com/0x1d/rcond/pkg/network"
"github.com/0x1d/rcond/pkg/system"
"github.com/0x1d/rcond/pkg/user"
@@ -287,3 +288,24 @@ func HandleShutdown(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"status": "success"})
}
func ClusterAgentWrapper(agent *cluster.Agent) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
HandleClusterMembers(w, r, agent)
}
}
func HandleClusterMembers(w http.ResponseWriter, r *http.Request, agent *cluster.Agent) {
if agent == nil {
writeError(w, "cluster agent is not initialized", http.StatusInternalServerError)
return
}
members, err := agent.Members()
if err != nil {
writeError(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(members)
}