How can I get the country code number by passing the number in golang by using this library: https://godoc.org/github.com/nyaruka/phonenumbers?
Asked
Active
Viewed 4,231 times
-7
-
4You're not writing syntactically valid Go. – Jonathan Hall Mar 05 '19 at 19:21
-
2Most basic syntax questions are answered within the [Tour of Go](https://tour.golang.org) which only takes a few minutes to finish. – Adrian Mar 05 '19 at 19:24
-
1It looks like this is a machine-generated port of a Java library, complete with Java examples. This is why it's not working--you're trying to write Java in Go. – Jonathan Hall Mar 05 '19 at 19:24
-
I understand that the syntax is not valid for golang, but this is what i found in library documentation: https://godoc.org/github.com/nyaruka/phonenumbers, i'm just beginner in golang that's why i was thinking that maybe i'm missing something. – Ilie Soltanici Mar 05 '19 at 19:34
-
So what is your question? You seem to be asking why that code doesn't work. – Jonathan Hall Mar 05 '19 at 19:35
1 Answers
9
The answer which I was looking is how to get the country code by passing the phone number only, this is the solution which is working perfectly.
num, err := phonenumbers.Parse("+123456789", "")
if err != nil {
fmt.Println(err.Error())
}
regionNumber := phonenumbers.GetRegionCodeForNumber(num)
countryCode := phonenumbers.GetCountryCodeForRegion(regionNumber)
fmt.Println(countryCode)
Thank you Yacacov for the hint ;)

Ilie Soltanici
- 377
- 2
- 16