From 48f5867c09a8e30a7d8aca471af6663fc32fcbd7 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Sun, 13 Apr 2025 10:57:39 +0200 Subject: refactor: use maps for template data --- lexsurf.go | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/lexsurf.go b/lexsurf.go index 5d25a6a..b9dbb66 100644 --- a/lexsurf.go +++ b/lexsurf.go @@ -58,9 +58,9 @@ func handler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("page not found")) return } - err := tpl.ExecuteTemplate(w, "index.html", StartPageContext{ - Countries: countries, - Domain: r.Host, + err := tpl.ExecuteTemplate(w, "index.html", map[string]any{ + "Countries": countries, + "Domain": r.Host, }) if err != nil { log.Fatal(err) @@ -100,10 +100,12 @@ func handler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusBadRequest) } } - err := tpl.ExecuteTemplate(w, "search.html", SearchContext{ - TLD: cc, - Domain: host, - Country: countries[cc], + _, hasJSONLaws := lawsByCC[cc] + err := tpl.ExecuteTemplate(w, "search.html", map[string]any{ + "TLD": cc, + "Domain": host, + "Country": countries[cc], + "HasJSONLaws": hasJSONLaws, }) if err != nil { log.Fatal(err) @@ -126,19 +128,3 @@ type country struct { func (c country) HasPlaceholder() bool { return strings.Contains(c.SearchURL, "%s") } - -func (c SearchContext) HasJSONLaws() bool { - _, ok := lawsByCC[c.TLD] - return ok -} - -type StartPageContext struct { - Countries map[string]country - Domain string -} - -type SearchContext struct { - TLD string - Domain string - Country country -} -- cgit v1.2.3