mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2024-11-16 17:07:36 +00:00
b68f626ce2
Will be useful for future development using standard `net/http`.
31 lines
690 B
Go
31 lines
690 B
Go
package handler
|
|
|
|
import (
|
|
"github.com/ditatompel/xmr-remote-nodes/internal/monero"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
// checkProberMW is a middleware to check prober API key
|
|
func (s *fiberServer) checkProberMW(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()
|
|
}
|