feat: health now checks databases
This commit is contained in:
parent
b8c033d04e
commit
752fcdbe19
|
@ -1,7 +1,30 @@
|
|||
package handler
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
import (
|
||||
"context"
|
||||
"jokes-bapak2-api/app/v1/models"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func Health(c *fiber.Ctx) error {
|
||||
return c.SendStatus(fiber.StatusNoContent)
|
||||
// Ping REDIS database
|
||||
err := redis.Ping(context.Background()).Err()
|
||||
if err != nil {
|
||||
return c.
|
||||
Status(fiber.StatusServiceUnavailable).
|
||||
JSON(models.ResponseError{
|
||||
Error: "REDIS: " + err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
_, err = db.Query(context.Background(), "SELECT \"id\" FROM \"jokesbapak2\" LIMIT 1")
|
||||
if err != nil {
|
||||
return c.
|
||||
Status(fiber.StatusServiceUnavailable).
|
||||
JSON(models.ResponseError{
|
||||
Error: "POSTGRESQL: " + err.Error(),
|
||||
})
|
||||
}
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue