forked from sundowndev/phoneinfoga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal.go
31 lines (25 loc) · 871 Bytes
/
local.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package scanners
import (
"github.com/nyaruka/phonenumbers"
"gopkg.in/sundowndev/phoneinfoga.v2/pkg/utils"
)
// LocalScan performs a local scan of a phone
// number using phonenumbers library
func LocalScan(number string) (res *Number, err error) {
n := "+" + utils.FormatNumber(number)
country := utils.ParseCountryCode(n)
num, err := phonenumbers.Parse(n, country)
if err != nil {
return nil, err
}
res = &Number{
RawLocal: utils.FormatNumber(phonenumbers.Format(num, phonenumbers.NATIONAL)),
Local: phonenumbers.Format(num, phonenumbers.NATIONAL),
E164: phonenumbers.Format(num, phonenumbers.E164),
International: utils.FormatNumber(phonenumbers.Format(num, phonenumbers.E164)),
CountryCode: num.GetCountryCode(),
Country: country,
Carrier: num.GetPreferredDomesticCarrierCode(),
}
return res, nil
}