diff options
author | Martin Fischer <martin@push-f.com> | 2025-04-13 10:57:39 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2025-04-13 14:30:44 +0200 |
commit | 48f5867c09a8e30a7d8aca471af6663fc32fcbd7 (patch) | |
tree | 411ef2fe81a88463ebd0116584182cb56d04ed7e | |
parent | 6135e4cc5c6ad08f2e94cc35d563df343a19b931 (diff) |
refactor: use maps for template data
-rw-r--r-- | lexsurf.go | 32 |
1 files changed, 9 insertions, 23 deletions
@@ -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 -} |