Add statuspage package with service, handler, and types for exposing platform health. Implement GET /api/v1/status endpoint returning operational status, component health (API, database, gateway runtime), and control plane summary counts. Add Service.Snapshot method querying database connectivity, user/device/gateway/service/policy counts, connected device count via handshake timestamps, and gateway runtime tel
25 lines
482 B
Go
25 lines
482 B
Go
package statuspage
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"nexavpn/backend/internal/apiutil"
|
|
)
|
|
|
|
type Handler struct {
|
|
service *Service
|
|
}
|
|
|
|
func NewHandler(service *Service) *Handler {
|
|
return &Handler{service: service}
|
|
}
|
|
|
|
func (h *Handler) PublicStatus(w http.ResponseWriter, r *http.Request) {
|
|
snapshot := h.service.Snapshot(r.Context())
|
|
statusCode := http.StatusOK
|
|
if snapshot.Status != "operational" {
|
|
statusCode = http.StatusServiceUnavailable
|
|
}
|
|
apiutil.JSON(w, statusCode, snapshot)
|
|
}
|