micrach/controllers/captcha_controller.go
Yanislav Igonin c8c9850625
Refactoring - Fiber (#14)
* add fiber

* disable gin, enable fiber

* gradually enabling app setup

* change env

* add routes

* add static

* connect template engine

* add simple load test

* make it executable

* add rate limiter

* doc

* connect get threads controller

* clean

* add compression middleware

* add etag middleware

* lint

* add recover middleware

* check isFromLocal method

* connect get thread by id controller

* connect create thread controller

* connect captcha controller

* connect update thread controller

* rename file

* playing with css

* connect gateway controller
2022-04-09 15:16:09 +03:00

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())
}