diff options
author | Martin Fischer <martin@push-f.com> | 2025-04-06 10:10:37 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2025-04-13 20:19:48 +0200 |
commit | 16b01fd1dfb8797b5529ea444f5b26cd26be9c3c (patch) | |
tree | dde08739bab75ab51d29a28455ed225b56dffc98 | |
parent | 96166f3f17a048499cd6c9af95e81d8f4c655978 (diff) |
refactor: embed countries.json and templates in binary
-rw-r--r-- | lexsurf.go | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -1,6 +1,7 @@ package main import ( + "embed" "encoding/json" "io/ioutil" "log" @@ -11,6 +12,9 @@ import ( "text/template" ) +//go:embed countries.json +var countriesJSON []byte + func main() { domain := os.Getenv("DOMAIN") if domain == "" { @@ -18,10 +22,9 @@ func main() { } var handler = handler{domain: domain, lawsByCC: map[string]map[string]law{}} - text, _ := ioutil.ReadFile("countries.json") - err := json.Unmarshal(text, &handler.countries) + err := json.Unmarshal(countriesJSON, &handler.countries) if err != nil { - log.Fatal("search.json", err) + log.Fatal("countries.json ", err) } lawFiles, err := ioutil.ReadDir("laws") @@ -51,9 +54,12 @@ func main() { log.Fatal(http.ListenAndServe(":8000", nil)) } +//go:embed templates +var templates embed.FS + var tpl, _ = template.New("").Funcs(template.FuncMap{ "ToUpper": strings.ToUpper, -}).ParseGlob("templates/*") +}).ParseFS(templates, "templates/*") type handler struct { domain string |