2023-01-26 06:00:02 -08:00
|
|
|
package infrastructure
|
2022-12-05 12:41:37 -08:00
|
|
|
|
2023-01-27 07:58:37 -08:00
|
|
|
import (
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/wormhole-foundation/wormhole-explorer/api/handlers/infrastructure"
|
2023-02-01 05:46:22 -08:00
|
|
|
"github.com/wormhole-foundation/wormhole-explorer/api/internal/build"
|
2023-01-27 07:58:37 -08:00
|
|
|
)
|
2022-12-05 12:41:37 -08:00
|
|
|
|
|
|
|
// Controller definition.
|
|
|
|
type Controller struct {
|
2023-01-27 07:58:37 -08:00
|
|
|
srv *infrastructure.Service
|
2022-12-05 12:41:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewController creates a Controller instance.
|
2023-01-27 07:58:37 -08:00
|
|
|
func NewController(serv *infrastructure.Service) *Controller {
|
2022-12-05 12:41:37 -08:00
|
|
|
return &Controller{srv: serv}
|
|
|
|
}
|
|
|
|
|
2023-02-01 09:11:40 -08:00
|
|
|
// HealthCheck is the HTTP route handler for the endpoint `GET /api/v1/health`.
|
2023-01-25 11:19:14 -08:00
|
|
|
// HealthCheck godoc
|
|
|
|
// @Description Health check
|
2023-08-18 09:30:19 -07:00
|
|
|
// @Tags wormholescan
|
2023-01-25 11:19:14 -08:00
|
|
|
// @ID health-check
|
|
|
|
// @Success 200 {object} object{status=string}
|
|
|
|
// @Failure 400
|
|
|
|
// @Failure 500
|
|
|
|
// @Router /api/v1/health [get]
|
2022-12-05 12:41:37 -08:00
|
|
|
func (c *Controller) HealthCheck(ctx *fiber.Ctx) error {
|
|
|
|
return ctx.JSON(struct {
|
|
|
|
Status string `json:"status"`
|
|
|
|
}{Status: "OK"})
|
|
|
|
}
|
|
|
|
|
2023-02-01 09:11:40 -08:00
|
|
|
// ReadyCheck is the HTTP handler for the endpoint `GET /api/v1/ready`.
|
2023-01-25 11:19:14 -08:00
|
|
|
// ReadyCheck godoc
|
|
|
|
// @Description Ready check
|
2023-08-18 09:30:19 -07:00
|
|
|
// @Tags wormholescan
|
2023-01-25 11:19:14 -08:00
|
|
|
// @ID ready-check
|
2023-02-01 09:11:40 -08:00
|
|
|
// @Success 200 {object} object{ready=string}
|
2023-01-25 11:19:14 -08:00
|
|
|
// @Failure 400
|
|
|
|
// @Failure 500
|
|
|
|
// @Router /api/v1/ready [get]
|
2022-12-05 12:41:37 -08:00
|
|
|
func (c *Controller) ReadyCheck(ctx *fiber.Ctx) error {
|
|
|
|
ready, _ := c.srv.CheckMongoServerStatus(ctx.Context())
|
|
|
|
if ready {
|
|
|
|
return ctx.Status(fiber.StatusOK).JSON(struct {
|
|
|
|
Ready string `json:"ready"`
|
|
|
|
}{Ready: "OK"})
|
|
|
|
}
|
|
|
|
return ctx.Status(fiber.StatusInternalServerError).JSON(struct {
|
|
|
|
Ready string `json:"ready"`
|
|
|
|
}{Ready: "NO"})
|
|
|
|
}
|
2023-02-01 05:46:22 -08:00
|
|
|
|
2023-02-01 09:11:40 -08:00
|
|
|
// VersionResponse is the JSON model for the 200 OK response in `GET /api/v1/version`.
|
|
|
|
type VersionResponse struct {
|
2023-02-02 12:19:28 -08:00
|
|
|
BuildDate string `json:"build_date"`
|
2023-02-01 09:11:40 -08:00
|
|
|
Build string `json:"build"`
|
|
|
|
Branch string `json:"branch"`
|
|
|
|
Machine string `json:"machine"`
|
|
|
|
User string `json:"user"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Version is the HTTP route handler for the endpoint `GET /api/v1/version`.
|
|
|
|
// Version godoc
|
|
|
|
// @Description Get version/release information.
|
2023-08-18 09:30:19 -07:00
|
|
|
// @Tags wormholescan
|
2023-02-01 09:11:40 -08:00
|
|
|
// @ID get-version
|
|
|
|
// @Success 200 {object} VersionResponse
|
2023-02-01 05:46:22 -08:00
|
|
|
// @Failure 400
|
|
|
|
// @Failure 500
|
|
|
|
// @Router /api/v1/version [get]
|
|
|
|
func (c *Controller) Version(ctx *fiber.Ctx) error {
|
2023-02-01 09:11:40 -08:00
|
|
|
return ctx.JSON(VersionResponse{
|
|
|
|
BuildDate: build.Time,
|
|
|
|
Branch: build.Branch,
|
|
|
|
Build: build.Build,
|
|
|
|
Machine: build.Machine,
|
|
|
|
User: build.User,
|
|
|
|
})
|
2023-02-01 05:46:22 -08:00
|
|
|
}
|