diff options
author | Martin Fischer <martin@push-f.com> | 2025-04-05 19:49:55 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2025-04-13 14:30:41 +0200 |
commit | 6135e4cc5c6ad08f2e94cc35d563df343a19b931 (patch) | |
tree | 464f73331c0a05eaf79e8359d6b10a66c3a95990 | |
parent | a4d568c16750dcaeab50692e103e24473ae22909 (diff) |
refactor: reorder lexsurf.go
-rw-r--r-- | lexsurf.go | 120 |
1 files changed, 60 insertions, 60 deletions
@@ -10,39 +10,41 @@ import ( "text/template" ) -type law struct { - Url string - Title string - Abbr string - Redir string -} - -type country struct { - Name string - SearchURL string `json:"search_url"` -} - -func (c country) HasPlaceholder() bool { - return strings.Contains(c.SearchURL, "%s") -} - -func (c SearchContext) HasJSONLaws() bool { - _, ok := lawsByCC[c.TLD] - return ok -} - var countries = map[string]country{} var lawsByCC = map[string]map[string]law{} -type StartPageContext struct { - Countries map[string]country - Domain string -} +func main() { + text, _ := ioutil.ReadFile("countries.json") + err := json.Unmarshal(text, &countries) + if err != nil { + log.Fatal("search.json", err) + } -type SearchContext struct { - TLD string - Domain string - Country country + lawFiles, err := ioutil.ReadDir("laws") + if err != nil { + log.Fatal(err) + } + for _, file := range lawFiles { + text, err := ioutil.ReadFile("laws/" + file.Name()) + if err != nil { + log.Fatal(file.Name(), err) + } + var laws []law + err = json.Unmarshal([]byte(text), &laws) + if err != nil { + log.Fatal(file.Name(), err) + } + cc := strings.SplitN(file.Name(), ".", 2)[0] + lawsByCC[cc] = map[string]law{} + for _, law := range laws { + if law.Redir != "" { + lawsByCC[cc][law.Redir] = law + } + } + } + http.HandleFunc("/", handler) + println("listening on 8000") + log.Fatal(http.ListenAndServe(":8000", nil)) } var tpl, _ = template.New("").Funcs(template.FuncMap{ @@ -109,36 +111,34 @@ func handler(w http.ResponseWriter, r *http.Request) { } } -func main() { - text, _ := ioutil.ReadFile("countries.json") - err := json.Unmarshal(text, &countries) - if err != nil { - log.Fatal("search.json", err) - } +type law struct { + Url string + Title string + Abbr string + Redir string +} - lawFiles, err := ioutil.ReadDir("laws") - if err != nil { - log.Fatal(err) - } - for _, file := range lawFiles { - text, err := ioutil.ReadFile("laws/" + file.Name()) - if err != nil { - log.Fatal(file.Name(), err) - } - var laws []law - err = json.Unmarshal([]byte(text), &laws) - if err != nil { - log.Fatal(file.Name(), err) - } - cc := strings.SplitN(file.Name(), ".", 2)[0] - lawsByCC[cc] = map[string]law{} - for _, law := range laws { - if law.Redir != "" { - lawsByCC[cc][law.Redir] = law - } - } - } - http.HandleFunc("/", handler) - println("listening on 8000") - log.Fatal(http.ListenAndServe(":8000", nil)) +type country struct { + Name string + SearchURL string `json:"search_url"` +} + +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 } |