-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
40 lines (36 loc) · 1010 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
package main
import (
_ "embed"
"github.com/gofiber/fiber/v2"
templts "github.com/magnuswahlstrand/htmx-experiments/components"
"log"
"os"
)
var isDev = os.Getenv("ENV") == "dev"
func main() {
app := fiber.New()
app.Get("/", func(c *fiber.Ctx) error {
w := templts.Page(serverVersion)
c.Set("Content-Type", "text/html")
return w.Render(c.Context(), c.Response().BodyWriter())
})
app.Static("/", "./static")
app.Get("/get", getHandler)
app.Get("/reload", reloadHandler)
app.Get("/color", colorHandler)
app.Get("/sse", sseHandler)
app.Get("/track", trackHandler)
app.Post("/slow", slowHandler)
contacts := app.Group("/contacts")
contacts.Put("/1", contactsUpdatePutHandler)
contacts.Get("/1", contactGetHandler)
contacts.Get("/1/edit", contactEditGetHandler)
app.Get("/click_to_load", clickToLoadHandler)
app.Get("/modal", modalHandler)
port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Printf("defaulting to port %s", port)
}
log.Fatal(app.Listen(":" + port))
}