xmr-remote-nodes/handler/middlewares.go
2024-05-30 13:40:57 +07:00

30 lines
592 B
Go

package handler
import (
"xmr-remote-nodes/internal/monero"
"github.com/gofiber/fiber/v2"
)
func CheckProber(c *fiber.Ctx) error {
key := c.Get(monero.ProberAPIKey)
if key == "" {
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
"status": "error",
"message": "Unauthorized",
"data": nil,
})
}
prober, err := monero.NewProber().CheckApi(key)
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)
return c.Next()
}