mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
6c2da4b2f5
Add version and commit_hash fields to the /ping endpoint response, sourced from the existing internal/version package (ldflags or Go build info). The frontend capabilities store reads these values and displays them as badges at the bottom of the Profile page.
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package handlers
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"github.com/memohai/memoh/internal/boot"
|
|
"github.com/memohai/memoh/internal/version"
|
|
)
|
|
|
|
type PingResponse struct {
|
|
Status string `json:"status"`
|
|
ContainerBackend string `json:"container_backend"`
|
|
SnapshotSupported bool `json:"snapshot_supported"`
|
|
Version string `json:"version"`
|
|
CommitHash string `json:"commit_hash"`
|
|
}
|
|
|
|
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",
|
|
Version: version.Version,
|
|
CommitHash: version.ShortCommitHash(),
|
|
})
|
|
}
|
|
|
|
func (*PingHandler) PingHead(c echo.Context) error {
|
|
return c.NoContent(http.StatusOK)
|
|
}
|