diff options
author | Martin Fischer <martin@push-f.com> | 2025-04-07 07:02:18 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2025-04-13 23:18:01 +0200 |
commit | 766ec45bb50c4e4335e7529f070e87af510c3914 (patch) | |
tree | 7ba687b40e09459c90b93ae58cef80a386cc580b /lex-serve/main.go | |
parent | 43c782b50fe9c5acbfd04139337873326015e27d (diff) |
refactor: convert countries.json to TOML
Diffstat (limited to 'lex-serve/main.go')
-rw-r--r-- | lex-serve/main.go | 16 |
1 files changed, 11 insertions, 5 deletions
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 { |