jokes-bapak2/api/app/v1/handler/health.go

31 lines
637 B
Go
Raw Normal View History

2021-07-09 12:13:19 +00:00
package handler
2021-07-15 05:55:28 +00:00
import (
"context"
"jokes-bapak2-api/app/v1/models"
"github.com/gofiber/fiber/v2"
)
2021-07-09 12:13:19 +00:00
func Health(c *fiber.Ctx) error {
2021-07-15 05:55:28 +00:00
// 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)
2021-07-09 12:13:19 +00:00
}