You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/a-h/templ"
|
|
|
|
)
|
|
|
|
|
|
|
|
var clicks uint = 0
|
|
|
|
|
|
|
|
func generateHandler(template func() templ.Component, handler func()) func(http.ResponseWriter, *http.Request) {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
|
|
template().Render(context.Background(), w)
|
|
|
|
handler()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
http.Handle("/", http.FileServer(http.Dir("static")))
|
|
|
|
http.HandleFunc("/api/click", generateHandler(
|
|
|
|
func() templ.Component { return Click(clicks) },
|
|
|
|
func() { clicks++ },
|
|
|
|
))
|
|
|
|
http.ListenAndServe(":3333", nil)
|
|
|
|
}
|