-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (44 loc) · 828 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"log"
"os"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/template/html/v2"
"github.com/joho/godotenv"
)
func main() {
loadEnvironment()
engine := html.New("./views", ".html")
engine.Reload(true)
engine.Debug(true)
app := fiber.New(fiber.Config{
Views: engine,
})
app.Get("/", func(c fiber.Ctx) error {
return c.Render("index", fiber.Map{
"MapboxToken": os.Getenv("MAPBOX_TOKEN"),
})
})
startServer(app)
}
func startServer(app *fiber.App) {
port := getPort()
log.Fatal(app.Listen(port))
}
func getPort() string {
port := os.Getenv("PORT")
if port == "" {
port = ":3000"
} else {
port = ":" + port
}
return port
}
func loadEnvironment() {
if os.Getenv("DEV") != "" {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
}
}