54 lines
1,004 B
Go
54 lines
1,004 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gofiber/template/html/v2"
|
|
)
|
|
|
|
func main() {
|
|
engine := html.New("views", ".html")
|
|
|
|
app := fiber.New(fiber.Config{
|
|
Views: engine,
|
|
BodyLimit: 10 * 1024 * 1024 * 1024, // 1GiB
|
|
})
|
|
|
|
app.Static("/", "static")
|
|
|
|
app.Get("/", func(c *fiber.Ctx) error {
|
|
return c.Render("index", fiber.Map{
|
|
"Stylenames": []string{"colors", "main", "index"},
|
|
})
|
|
})
|
|
|
|
app.Post("/generate", func(c *fiber.Ctx) error {
|
|
c.Accepts("multipart/form-data")
|
|
file, err := c.FormFile("file")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
openedFile, err := file.Open()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
data, err := io.ReadAll(openedFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
img, err := HilbertCurveGenerateByteImage(data)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
c.Type("bmp")
|
|
c.Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", file.Filename+".bmp"))
|
|
return c.Send(img)
|
|
})
|
|
|
|
log.Fatal(app.Listen(":3000"))
|
|
}
|