feat: 添加健康检查
This commit is contained in:
parent
af232c2ecf
commit
ea3ef541e2
9
health/health.go
Normal file
9
health/health.go
Normal 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",
|
||||||
|
})
|
||||||
|
}
|
7
main.go
7
main.go
@ -4,18 +4,25 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.lxtend.com/qqbot/health"
|
||||||
"git.lxtend.com/qqbot/sqlite3"
|
"git.lxtend.com/qqbot/sqlite3"
|
||||||
wsclient "git.lxtend.com/qqbot/ws_client"
|
wsclient "git.lxtend.com/qqbot/ws_client"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// 创建 WebSocket 客户端
|
// 创建 WebSocket 客户端
|
||||||
|
gin.SetMode(gin.ReleaseMode)
|
||||||
sqlite3.InitDB()
|
sqlite3.InitDB()
|
||||||
client, err := wsclient.NewWebSocketClient("ws", "localhost:3001", "")
|
client, err := wsclient.NewWebSocketClient("ws", "localhost:3001", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print("Error creating WebSocket client:", err)
|
log.Print("Error creating WebSocket client:", err)
|
||||||
}
|
}
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
|
ginServer := gin.New()
|
||||||
|
engine := ginServer.Group("/health")
|
||||||
|
engine.GET("/ping", health.HealthHandler)
|
||||||
|
go ginServer.Run(":3434")
|
||||||
for {
|
for {
|
||||||
time.Sleep(1000 * time.Second)
|
time.Sleep(1000 * time.Second)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user