Skip to content

Instantly share code, notes, and snippets.

@thanhdatvo
Last active April 30, 2020 18:41
Show Gist options
  • Save thanhdatvo/251b9a96bc950117fa3cfd43ac024d88 to your computer and use it in GitHub Desktop.
Save thanhdatvo/251b9a96bc950117fa3cfd43ac024d88 to your computer and use it in GitHub Desktop.
Gofiber start function
package main
import (
"gofiber/starter/routes"
"github.com/gofiber/fiber"
"github.com/gofiber/logger"
"github.com/gofiber/template"
)
func main() {
app := fiber.New()
// view engine setup
app.Settings.TemplateFolder = "./views"
app.Settings.TemplateEngine = template.Pug()
app.Settings.TemplateExtension = ".jade"
app.Use(logger.New())
app.Static("/", "./public")
routes.SetupIndexRouter(app.Group("/"))
routes.SetupUsersRouter(app.Group("/users"))
// catch 404 error handler
app.Use("/*", func(c *fiber.Ctx) {
bind := fiber.Map{
"title": "Page not found",
"message": "Page not found",
"error": map[string]interface{}{
"status": 400,
"stack": "",
},
}
// render the error page
if err := c.Render("./error", bind); err != nil {
c.Status(500).Send(err.Error())
}
})
app.Listen(3000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment