mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"github.com/memohai/memoh/internal/boot"
|
|
)
|
|
|
|
type PingResponse struct {
|
|
Status string `json:"status"`
|
|
ContainerBackend string `json:"container_backend"`
|
|
SnapshotSupported bool `json:"snapshot_supported"`
|
|
}
|
|
|
|
type PingHandler struct {
|
|
logger *slog.Logger
|
|
runtime *boot.RuntimeConfig
|
|
}
|
|
|
|
func NewPingHandler(log *slog.Logger, rc *boot.RuntimeConfig) *PingHandler {
|
|
return &PingHandler{
|
|
logger: log.With(slog.String("handler", "ping")),
|
|
runtime: rc,
|
|
}
|
|
}
|
|
|
|
func (h *PingHandler) Register(e *echo.Echo) {
|
|
e.GET("/ping", h.Ping)
|
|
e.HEAD("/health", h.PingHead)
|
|
}
|
|
|
|
// Ping godoc
|
|
// @Summary Health check with server capabilities
|
|
// @Tags system
|
|
// @Success 200 {object} PingResponse
|
|
// @Router /ping [get].
|
|
func (h *PingHandler) Ping(c echo.Context) error {
|
|
return c.JSON(http.StatusOK, PingResponse{
|
|
Status: "ok",
|
|
ContainerBackend: h.runtime.ContainerBackend,
|
|
SnapshotSupported: h.runtime.ContainerBackend != "apple",
|
|
})
|
|
}
|
|
|
|
func (*PingHandler) PingHead(c echo.Context) error {
|
|
return c.NoContent(http.StatusOK)
|
|
}
|