xmr-remote-nodes/handler/middlewares.go

34 lines
672 B
Go
Raw Normal View History

package handler
import (
"xmr-remote-nodes/internal/database"
"xmr-remote-nodes/internal/repo"
2024-05-04 19:52:22 +07:00
"github.com/gofiber/fiber/v2"
)
2024-05-04 19:52:22 +07:00
func CheckProber(c *fiber.Ctx) error {
key := c.Get("X-Prober-Api-Key")
if key == "" {
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
"status": "error",
"message": "Unauthorized",
"data": nil,
})
}
proberRepo := repo.NewProberRepo(database.GetDB())
prober, err := proberRepo.CheckApi(key)
if err != nil {
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
"status": "error",
"message": "No API key match",
"data": nil,
})
}
2024-05-05 01:42:47 +07:00
c.Locals("prober_id", prober.Id)
2024-05-04 19:52:22 +07:00
return c.Next()
}