From 766ec45bb50c4e4335e7529f070e87af510c3914 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Mon, 7 Apr 2025 07:02:18 +0200 Subject: refactor: convert countries.json to TOML --- lex-serve/main.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'lex-serve/main.go') diff --git a/lex-serve/main.go b/lex-serve/main.go index 07dba19..ac67ad4 100644 --- a/lex-serve/main.go +++ b/lex-serve/main.go @@ -11,10 +11,12 @@ import ( "net/url" "os" "strings" + + "github.com/BurntSushi/toml" ) -//go:embed countries.json -var countriesJSON []byte +//go:embed countries.toml +var countriesTOML []byte func main() { log := slog.New(slog.NewTextHandler(os.Stderr, nil)) @@ -32,9 +34,13 @@ func main() { } var handler = handler{logger: log, domain: domain, lawsByCC: map[string]map[string]law{}} - err := json.Unmarshal(countriesJSON, &handler.countries) + meta, err := toml.NewDecoder(bytes.NewReader(countriesTOML)).Decode(&handler.countries) if err != nil { - log.Error("failed to parse countries.json", Error(err)) + log.Error("failed to parse countries.toml", Error(err)) + os.Exit(1) + } + if len(meta.Undecoded()) != 0 { + log.Error("unknown keys in countries.toml", "keys", meta.Undecoded()) os.Exit(1) } @@ -169,7 +175,7 @@ type law struct { type country struct { Name string - SearchURL string `json:"search_url"` + SearchURL string `toml:"search-url"` } func (c country) HasPlaceholder() bool { -- cgit v1.2.3