From ea3ef541e22d0d504be228c812b30216de6d0802 Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Tue, 15 Oct 2024 23:06:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=81=A5=E5=BA=B7?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- health/health.go | 9 +++++++++ main.go | 7 +++++++ 2 files changed, 16 insertions(+) create mode 100644 health/health.go diff --git a/health/health.go b/health/health.go new file mode 100644 index 0000000..d31371e --- /dev/null +++ b/health/health.go @@ -0,0 +1,9 @@ +package health + +import "github.com/gin-gonic/gin" + +func HealthHandler(c *gin.Context) { + c.JSON(200, gin.H{ + "message": "pong", + }) +} diff --git a/main.go b/main.go index 42845d3..1320890 100644 --- a/main.go +++ b/main.go @@ -4,18 +4,25 @@ import ( "log" "time" + "git.lxtend.com/qqbot/health" "git.lxtend.com/qqbot/sqlite3" wsclient "git.lxtend.com/qqbot/ws_client" + "github.com/gin-gonic/gin" ) func main() { // 创建 WebSocket 客户端 + gin.SetMode(gin.ReleaseMode) sqlite3.InitDB() client, err := wsclient.NewWebSocketClient("ws", "localhost:3001", "") if err != nil { log.Print("Error creating WebSocket client:", err) } defer client.Close() + ginServer := gin.New() + engine := ginServer.Group("/health") + engine.GET("/ping", health.HealthHandler) + go ginServer.Run(":3434") for { time.Sleep(1000 * time.Second) }