From f2afc2a50c68f527683b527ffc92da135c314f22 Mon Sep 17 00:00:00 2001 From: hailin Date: Tue, 17 Jun 2025 23:06:58 +0800 Subject: [PATCH] . --- Dockerfile | 2 ++ main.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/Dockerfile b/Dockerfile index 76d3038..f55e245 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,6 +41,8 @@ RUN apt-get update && apt-get install -y \ WORKDIR /root/ COPY --from=builder /app/license-server . +HEALTHCHECK --interval=60s --timeout=3s --start-period=10s --retries=3 CMD curl -f http://localhost:13579/api/health || exit 1 + EXPOSE 13579 CMD ["./license-server"] diff --git a/main.go b/main.go index 6cce885..f76ddbd 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "license-server/license" "license-server/storage" + "time" "github.com/gofiber/fiber/v2" ) @@ -12,6 +13,14 @@ func main() { license.InitCrypto(db) app := fiber.New() + // --- 简单健康检查 --- + app.Get("/api/health", func(c *fiber.Ctx) error { + return c.JSON(fiber.Map{ + "status": "ok", + "ts": time.Now().Unix(), + }) + }) + app.Post("/api/license/generate", license.GenerateLicenseHandler(db)) app.Post("/api/license/activate", license.ActivateLicenseHandler(db)) app.Post("/api/license/validate", license.ValidateLicenseHandler(db))