-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
40 lines (33 loc) · 790 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 (
"net/http"
"github.com/gin-gonic/gin"
"machinelearning.one/go-htmx/compose/context"
"machinelearning.one/go-htmx/compose/logger"
"machinelearning.one/go-htmx/compose/server"
)
func main() {
ctx := context.Context()
lg := logger.New("trace")
ctx = lg.WithContext(ctx)
port := uint(8080)
data := struct {
Count int
}{0}
fn := server.Fn{
HTTPMethod: "POST",
RelativePath: "/clicked",
Handlers: []gin.HandlerFunc{
func(c *gin.Context) {
data.Count += 1
lg.Trace().Int("count", data.Count).Msg("clicked")
c.HTML(http.StatusOK, "clicked.frag.html", data)
},
},
}
lg.Trace().Msgf("starting server on port %d", port)
err := server.Run(ctx, port, fn)
if err != nil {
lg.Fatal().Err(err).Msg("failed to start server")
}
}