Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion countries.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package sanja
import (
_ "embed"
"encoding/json"
"sync"
)

//go:embed countries.json
var countriesData []byte

func getCountries() []Country {
var getCountries = sync.OnceValue(parseCountries)

func parseCountries() []Country {
var result []Country
if err := json.Unmarshal(countriesData, &result); err != nil {
panic("sanja: failed to parse countries data: " + err.Error())
Expand Down
2 changes: 0 additions & 2 deletions country.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func (n *Normalizer) ValidatePhoneNumber(phone, countryA2 string) error {
return ErrInvalidPhoneNumber
}


var matchedCode string
for _, code := range splitDialingCodes(country.DialingCode) {
if strings.HasPrefix(cleaned, "+"+code) || strings.HasPrefix(cleaned, code) {
Expand All @@ -59,7 +58,6 @@ func (n *Normalizer) ValidatePhoneNumber(phone, countryA2 string) error {
return fmt.Errorf("%w: expected code for %s", ErrPhoneNumberAndCountryCodeMismatch, country.Name)
}


withoutPlus := strings.TrimPrefix(cleaned, "+")
subscriber := withoutPlus[len(matchedCode):]

Expand Down
Loading