summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2025-04-13 10:57:39 +0200
committerMartin Fischer <martin@push-f.com>2025-04-13 14:30:44 +0200
commit48f5867c09a8e30a7d8aca471af6663fc32fcbd7 (patch)
tree411ef2fe81a88463ebd0116584182cb56d04ed7e
parent6135e4cc5c6ad08f2e94cc35d563df343a19b931 (diff)
refactor: use maps for template data
-rw-r--r--lexsurf.go32
1 files 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
-}