mirror of
https://github.com/yanislav-igonin/micrach
synced 2025-04-20 03:40:33 +03:00
23 lines
482 B
Go
23 lines
482 B
Go
package controllers
|
|
|
|
import (
|
|
"bytes"
|
|
"log"
|
|
|
|
"github.com/dchest/captcha"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func GetCaptcha(c *fiber.Ctx) error {
|
|
ID := c.Params("captchaID")
|
|
var content bytes.Buffer
|
|
err := captcha.WriteImage(&content, ID, captcha.StdWidth, captcha.StdHeight)
|
|
if err != nil {
|
|
log.Println("error:", err)
|
|
return c.Status(fiber.StatusInternalServerError).Render("pages/500", nil)
|
|
}
|
|
|
|
c.Context().SetContentType("image/png")
|
|
return c.Send(content.Bytes())
|
|
}
|