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) }