| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package functions
-
- import (
- "time"
-
- "github.com/gin-gonic/gin"
-
- "git.x2erp.com/qdy/go-base/types"
- "git.x2erp.com/qdy/go-db/factory"
- )
-
- // HealthHandler 返回一个处理函数
- func HealthHandler(dbFactory *factory.DBFactory, dbType string) gin.HandlerFunc {
- return func(c *gin.Context) {
-
- dbFactory.TestConnection(dbType)
- err := dbFactory.TestConnection(dbType)
- success := err == nil
-
- status := "DOWN"
- if success {
- status = "UP"
- }
-
- c.JSON(200, &types.QueryResult{
- Success: success,
- Data: map[string]interface{}{
- "status": status,
- "time": time.Now().Format(time.RFC3339),
- "database": dbType,
- "databaseStatus": status,
- },
- Error: func() string {
- if err != nil {
- return err.Error()
- }
- return ""
- }(),
- })
- }
- }
|