diff options
author | Mathias Magnusson <mathias@magnusson.space> | 2024-11-17 20:03:48 +0100 |
---|---|---|
committer | Mathias Magnusson <mathias@magnusson.space> | 2024-11-17 20:03:48 +0100 |
commit | 2778c52e4da52fd33f2df7fc9024252c2470b172 (patch) | |
tree | 1134be8e985f828e31c609ac061b1275ed35f972 /examples/basic.go | |
parent | 19fa57e67bcc4af13a252c17c0e18adab162d2d1 (diff) | |
download | hh-2778c52e4da52fd33f2df7fc9024252c2470b172.tar.gz |
use a template instead of a bunch of buffer.WriteString
Diffstat (limited to 'examples/basic.go')
-rw-r--r-- | examples/basic.go | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/examples/basic.go b/examples/basic.go index b26f8a9..856d682 100644 --- a/examples/basic.go +++ b/examples/basic.go @@ -3,38 +3,18 @@ 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:"optional,form"` - nextURL string `hh:"cookie,logout_next_url"` + r *http.Request + search string `hh:"form"` + year int `hh:"optional,form"` + offset int `hh:"form"` + 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:"optional,form"` - nextURL string `hh:"cookie,logout_next_url"` - }{r: r, search: search, year: year, offset: offset}) -} |