tren/main.go
ngn 4df8b90dae
All checks were successful
Build and publish the docker image / build (push) Successful in 58s
initial commit
Signed-off-by: ngn <ngn@ngn.tf>
2025-04-05 09:58:58 +03:00

54 lines
1.1 KiB
Go

package main
import (
"log"
"os"
"git.ngn.tf/ngn/tren/extract"
"git.ngn.tf/ngn/tren/routes"
"git.ngn.tf/ngn/tren/util"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html/v2"
)
func main() {
var (
extractor *extract.Extractor
err error
)
// configure logger
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
if extractor, err = extract.New(); err != nil {
log.Printf("failed to create an extractor: %s", err.Error())
os.Exit(1)
}
engine := html.New("./views", ".html")
app := fiber.New(fiber.Config{
AppName: "tren",
DisableStartupMessage: true,
ServerHeader: "",
Views: engine,
})
app.Static("/", "./static")
app.Use("*", func(c *fiber.Ctx) error {
c.Locals("extractor", extractor)
return c.Next()
})
// routes
app.Get("/", routes.GET_index)
app.Post("/translate", routes.POST_translate)
// all the other routes redirect to index
app.All("*", func(c *fiber.Ctx) error {
return util.RenderError(c, 404)
})
log.Printf("starting the web application on port 8080")
log.Fatal(app.Listen(":8080"))
}