Skip to content

Commit

Permalink
Merge pull request #3 from Clarilab/fix/map-constant-keys
Browse files Browse the repository at this point in the history
fix: use Language as key type in map
  • Loading branch information
MaxBreida authored Sep 14, 2023
2 parents d3c0f6a + 0c47f01 commit b809e41
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 257 deletions.
8 changes: 4 additions & 4 deletions countries.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func findCountryByAlpha3(query string) (*Mapping, error) {

func findCountryByNameOrNationality(query string) (*Mapping, error) {
for i := range mappings {
if isCountryNameOrNationality(mappings[i].Translations[string(EN)], query) ||
isCountryNameOrNationality(mappings[i].Translations[string(DE)], query) {
if isCountryNameOrNationality(mappings[i].Translations[EN], query) ||
isCountryNameOrNationality(mappings[i].Translations[DE], query) {
return &mappings[i], nil
}
}
Expand Down Expand Up @@ -96,7 +96,7 @@ func CountryName(query string) string {
return ""
}

return country.Translations[string(EN)].Common
return country.Translations[EN].Common
}

// CountryTranslation looks up any matching occurrence for the query and returns the country translation.
Expand All @@ -106,7 +106,7 @@ func CountryTranslation(query string, lang Language) (*Translation, error) {
return nil, ErrCountryNotFound
}

translation, ok := country.Translations[string(lang)]
translation, ok := country.Translations[lang]
if !ok {
return nil, ErrTranslationNotFound
}
Expand Down
2 changes: 1 addition & 1 deletion countries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestAlpha2(t *testing.T) {
country := countries.AllMappings()[i]

t.Run("find by country name", func(t *testing.T) {
alpha2 := countries.Alpha2(country.Translations[string(countries.EN)].Common)
alpha2 := countries.Alpha2(country.Translations[countries.EN].Common)
if country.Alpha2 != alpha2 {
t.Errorf("expected: %s, got: %s", country.Alpha2, alpha2)
}
Expand Down
Loading

0 comments on commit b809e41

Please sign in to comment.