initial commit
All checks were successful
Build and publish the docker image / build (push) Successful in 58s
All checks were successful
Build and publish the docker image / build (push) Successful in 58s
Signed-off-by: ngn <ngn@ngn.tf>
This commit is contained in:
53
main.go
Normal file
53
main.go
Normal file
@ -0,0 +1,53 @@
|
||||
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"))
|
||||
}
|
Reference in New Issue
Block a user