Feat v0.6.0 cluster registry (#36)
All checks were successful
All checks were successful
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #36.
This commit is contained in:
32
server/handlers/cluster.go
Normal file
32
server/handlers/cluster.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"switchboard-core/store"
|
||||
)
|
||||
|
||||
// ClusterHandler serves the admin cluster API.
|
||||
type ClusterHandler struct {
|
||||
stores store.Stores
|
||||
}
|
||||
|
||||
func NewClusterHandler(stores store.Stores) *ClusterHandler {
|
||||
return &ClusterHandler{stores: stores}
|
||||
}
|
||||
|
||||
// ListNodes returns all registered cluster nodes.
|
||||
// GET /api/v1/admin/cluster
|
||||
func (h *ClusterHandler) ListNodes(c *gin.Context) {
|
||||
nodes, err := h.stores.Cluster.ListNodes(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to list cluster nodes"})
|
||||
return
|
||||
}
|
||||
if nodes == nil {
|
||||
nodes = []store.ClusterNode{}
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": nodes})
|
||||
}
|
||||
Reference in New Issue
Block a user