fix: unable to start api

This commit is contained in:
Marvin Zhang
2024-11-22 21:19:17 +08:00
parent 7a322ae6c8
commit 858e5c2b89
6 changed files with 78 additions and 27 deletions

View File

@@ -0,0 +1,18 @@
package controllers
import (
"github.com/gin-gonic/gin"
"net/http"
)
func GetHealthFn(healthFn func() bool) func(c *gin.Context) {
return func(c *gin.Context) {
if healthFn() {
c.Writer.Write([]byte("ok"))
c.AbortWithStatus(http.StatusOK)
return
}
c.Writer.Write([]byte("not ready"))
c.AbortWithStatus(http.StatusServiceUnavailable)
}
}

View File

@@ -381,6 +381,13 @@ func InitRoutes(app *gin.Engine) (err error) {
})
// Register public routes that don't require authentication
RegisterActions(groups.AnonymousGroup, "/health", []Action{
{
Path: "",
Method: http.MethodGet,
HandlerFunc: GetHealthFn(func() bool { return true }),
},
})
RegisterActions(groups.AnonymousGroup, "/system-info", []Action{
{
Path: "",