-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (32 loc) · 670 Bytes
/
main.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
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"os"
"strings"
"github.com/aws/aws-lambda-go/lambda"
"github.com/nyaruka/phonenumbers"
)
func handler(phoneNumber string) (string, error) {
p, err := phonenumbers.Parse(phoneNumber, "US")
if err != nil {
return "", err
}
if !phonenumbers.IsValidNumber(p) {
return "", err
}
parsedPhone := strings.TrimPrefix(phonenumbers.Format(p, phonenumbers.RFC3966), "tel:")
return parsedPhone, nil
}
func main() {
if len(os.Getenv("AWS_EXECUTION_ENV")) == 0 {
phoneNumber := os.Args[1]
p, err := handler(phoneNumber)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(p)
}
return
}
lambda.Start(handler)
}