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 examples
import (
"log/slog"
"net/http"
"strconv"
)
// Big bungus function here!
//
//hh:route GET /admin/users
func adminUsersForm(w http.ResponseWriter, r struct {
r *http.Request
search, year string `hh:"form"`
offset int `hh:"form,optional"`
nextURL string `hh:"cookie,logout_next_url"`
}) {
_, _ = w.Write([]byte("ahahaha"))
slog.Info("get admin users form", "search", r.search, "offset", r.offset, "next-url", r.nextURL)
}
func hh_adminUsersForm[S any](s S, w http.ResponseWriter, r *http.Request) {
search := r.FormValue("search")
year := r.FormValue("year")
offset0 := r.FormValue("offset")
offset, err := strconv.Atoi(offset0)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(`Bad request. Invalid integer 'offset' in form/query`))
}
adminUsersForm(w, struct {
r *http.Request
search, year string `hh:"form"`
offset int `hh:"form,optional"`
nextURL string `hh:"cookie,logout_next_url"`
}{r: r, search: search, year: year, offset: offset})
}
|