All checks were successful
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
33 lines
719 B
Go
33 lines
719 B
Go
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})
|
|
}
|