xmr-remote-nodes/internal/handler/middlewares.go
Christian Ditaputratama c250e8e3bb
feat!: Moving handler to internal/handler
So people aware that the package is internal use and not using that
on their projects.
2024-07-07 01:42:29 +07:00

30 lines
614 B
Go

package handler
import (
"github.com/ditatompel/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()
}