xmr-remote-nodes/internal/handler/middlewares.go

31 lines
614 B
Go
Raw Normal View History

package handler
import (
"github.com/ditatompel/xmr-remote-nodes/internal/monero"
2024-05-04 12:52:22 +00:00
"github.com/gofiber/fiber/v2"
)
2024-05-04 12:52:22 +00:00
func CheckProber(c *fiber.Ctx) error {
2024-05-30 06:40:57 +00:00
key := c.Get(monero.ProberAPIKey)
2024-05-04 12:52:22 +00:00
if key == "" {
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
"status": "error",
"message": "Unauthorized",
"data": nil,
})
}
prober, err := monero.NewProber().CheckAPI(key)
2024-05-04 12:52:22 +00:00
if err != nil {
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
"status": "error",
"message": "No API key match",
"data": nil,
})
}
c.Locals("prober_id", prober.ID)
2024-05-04 12:52:22 +00:00
return c.Next()
}