Want to contribute? Fork me on Codeberg.org!
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.

29 lines
637 B

2 years ago
package main
import (
"context"
2 years ago
"log"
"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()
}
}
2 years ago
func main() {
http.Handle("/", http.FileServer(http.Dir("static")))
http.HandleFunc("/api/click", generateHandler(
func() templ.Component { return Click(clicks) },
func() { clicks++ },
))
2 years ago
log.Fatal(http.ListenAndServe(":3333", nil))
2 years ago
}