forked from gofiber/recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (29 loc) · 778 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"log"
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html"
"geoip/handlers"
)
func main() {
// Create new fiber instance
app := fiber.New(fiber.Config{
// Pass view engine
Views: html.New("./views", ".html"),
// Pass global error handler
ErrorHandler: handlers.Errors("./public/500.html"),
})
// Render index template with IP input value
app.Get("/", handlers.Render())
// Serve static assets
app.Static("/", "./public", fiber.Static{
Compress: true,
})
// Main GEO handler that is cached for 10 minutes
app.Get("/geo/:ip?", handlers.Cache(10*time.Minute), handlers.GEO())
// Handle 404 errors
app.Use(handlers.NotFound("./public/404.html"))
// Listen on port :3000
log.Fatal(app.Listen(":3000"))
}