feat: 添加健康检查

This commit is contained in:
lixiangwuxian 2024-10-15 23:06:27 +08:00
parent af232c2ecf
commit ea3ef541e2
2 changed files with 16 additions and 0 deletions

9
health/health.go Normal file
View File

@ -0,0 +1,9 @@
package health
import "github.com/gin-gonic/gin"
func HealthHandler(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
}

View File

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