feat: add health check

This commit is contained in:
seven.yu 2023-12-19 21:29:40 +08:00
parent 97030e27f8
commit 6aae057172
2 changed files with 18 additions and 0 deletions

17
controller/health.go Normal file
View File

@ -0,0 +1,17 @@
package controller
import (
"fmt"
"github.com/gin-gonic/gin"
"net/http"
"one-api/common"
)
func Health(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": fmt.Sprintf("One-api is healthy. Version: %s", common.Version),
"data": "",
})
return
}

View File

@ -13,6 +13,7 @@ func SetApiRouter(router *gin.Engine) {
apiRouter.Use(gzip.Gzip(gzip.DefaultCompression))
apiRouter.Use(middleware.GlobalAPIRateLimit())
{
apiRouter.GET("/health", controller.Health)
apiRouter.GET("/status", controller.GetStatus)
apiRouter.GET("/notice", controller.GetNotice)
apiRouter.GET("/about", controller.GetAbout)