diff --git a/Makefile b/Makefile deleted file mode 100644 index f1934f8..0000000 --- a/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -build: - mkdir -p functions - cd cmd/phoneserver && go build -ldflags "-X main.Version=`git describe --tags`" -o ../../functions/phoneserver . diff --git a/README.md b/README.md index 78058ef..e122492 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,6 @@ golang port of Google's libphonenumber, forked from [libphonenumber from ttacon](https://github.com/ttacon/libphonenumber) which in turn is a port of the original [Java library](https://github.com/googlei18n/libphonenumber/tree/master/java/libphonenumber/src/com/google/i18n/phonenumbers). -You can see a live demo of the number parsing of the master branch of this library at [https://phonenumbers.temba.io/](https://phonenumbers.temba.io) Compare results with the official [Google Java version](https://rawgit.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/demo-compiled.html). - This fork fixes quite a few bugs and more closely follows the official Java implementation. It also adds the `buildmetadata` cmd to allow for rebuilding the metadata protocol buffers, country code to region maps and timezone prefix maps. We keep this library up to date with the upstream Google repo as metadata changes take place, usually no more than a few days behind official Google releases. This library is used daily in production for parsing and validation of numbers across the world, so is well maintained. Please open an issue if you encounter any problems, we'll do our best to address them. diff --git a/cmd/phoneparser/go.mod b/cmd/phoneparser/go.mod deleted file mode 100644 index 84e34ed..0000000 --- a/cmd/phoneparser/go.mod +++ /dev/null @@ -1,12 +0,0 @@ -module github.com/nyaruka/phonenumbers/cmd/phoneparser - -go 1.19 - -replace github.com/nyaruka/phonenumbers => ../../ - -require github.com/nyaruka/phonenumbers v0.0.0-00010101000000-000000000000 - -require ( - golang.org/x/text v0.14.0 // indirect - google.golang.org/protobuf v1.33.0 // indirect -) diff --git a/cmd/phoneparser/go.sum b/cmd/phoneparser/go.sum deleted file mode 100644 index a901708..0000000 --- a/cmd/phoneparser/go.sum +++ /dev/null @@ -1,10 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/cmd/phoneparser/main.go b/cmd/phoneparser/main.go index 15dd6b2..401ce14 100644 --- a/cmd/phoneparser/main.go +++ b/cmd/phoneparser/main.go @@ -17,15 +17,11 @@ func main() { num, err := phonenumbers.Parse(os.Args[1], os.Args[2]) if err != nil { fmt.Printf("Error parsing number: %s\n", err) + os.Exit(1) } - metadata, err := phonenumbers.Parse(os.Args[1], os.Args[2]) - if err != nil { - fmt.Printf("error parsing phone", err.Error()) - } fmt.Printf(" E164: %s\n", phonenumbers.Format(num, phonenumbers.E164)) fmt.Printf("National Dialing: %s\n", phonenumbers.Format(num, phonenumbers.NATIONAL)) fmt.Printf(" National: %d\n", *num.NationalNumber) - fmt.Printf(" IsValid: %s\n", strconv.FormatBool(phonenumbers.IsValidNumber(metadata))) - + fmt.Printf(" IsValid: %s\n", strconv.FormatBool(phonenumbers.IsValidNumber(num))) } diff --git a/cmd/phoneserver/go.mod b/cmd/phoneserver/go.mod deleted file mode 100644 index bbbddb0..0000000 --- a/cmd/phoneserver/go.mod +++ /dev/null @@ -1,15 +0,0 @@ -module github.com/nyaruka/phonenumbers/cmd/phoneserver - -go 1.19 - -replace github.com/nyaruka/phonenumbers => ../../ - -require ( - github.com/aws/aws-lambda-go v1.13.1 - github.com/nyaruka/phonenumbers v0.0.0-00010101000000-000000000000 -) - -require ( - golang.org/x/text v0.14.0 // indirect - google.golang.org/protobuf v1.33.0 // indirect -) diff --git a/cmd/phoneserver/go.sum b/cmd/phoneserver/go.sum deleted file mode 100644 index f9d9417..0000000 --- a/cmd/phoneserver/go.sum +++ /dev/null @@ -1,20 +0,0 @@ -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/aws/aws-lambda-go v1.13.1 h1:qVIOD3UrEUo4amwgEBu6AI0CfnBsp71XJEYU05RbQ1k= -github.com/aws/aws-lambda-go v1.13.1/go.mod h1:z4ywteZ5WwbIEzG0tXizIAUlUwkTNNknX4upd5Z5XJM= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVUZZQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/cmd/phoneserver/main.go b/cmd/phoneserver/main.go deleted file mode 100644 index 2af237e..0000000 --- a/cmd/phoneserver/main.go +++ /dev/null @@ -1,74 +0,0 @@ -package main - -import ( - "encoding/json" - "net/http" - - "github.com/aws/aws-lambda-go/events" - "github.com/aws/aws-lambda-go/lambda" - "github.com/nyaruka/phonenumbers" -) - -var Version = "dev" - -type errorResponse struct { - Message string `json:"message"` - Error string `json:"error"` -} - -type successResponse struct { - NationalNumber uint64 `json:"national_number"` - CountryCode int32 `json:"country_code"` - IsPossible bool `json:"is_possible"` - IsValid bool `json:"is_valid"` - InternationalFormatted string `json:"international_formatted"` - NationalFormatted string `json:"national_formatted"` - Version string `json:"version"` -} - -func writeResponse(status int, body interface{}) (events.APIGatewayProxyResponse, error) { - js, err := json.MarshalIndent(body, "", " ") - if err != nil { - return events.APIGatewayProxyResponse{ - StatusCode: 500, - Body: err.Error(), - }, nil - } - - return events.APIGatewayProxyResponse{ - StatusCode: 200, - Body: string(js), - Headers: map[string]string{"Content-Type": "application/json"}, - }, nil -} - -func parse(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { - phone := request.QueryStringParameters["phone"] - - // required phone number - if phone == "" { - return writeResponse(http.StatusBadRequest, errorResponse{"missing body", "missing 'phone' parameter"}) - } - - // optional country code - country := request.QueryStringParameters["country"] - - metadata, err := phonenumbers.Parse(phone, country) - if err != nil { - return writeResponse(http.StatusBadRequest, errorResponse{"error parsing phone", err.Error()}) - } - - return writeResponse(http.StatusOK, successResponse{ - NationalNumber: *metadata.NationalNumber, - CountryCode: *metadata.CountryCode, - IsPossible: phonenumbers.IsPossibleNumber(metadata), - IsValid: phonenumbers.IsValidNumber(metadata), - NationalFormatted: phonenumbers.Format(metadata, phonenumbers.NATIONAL), - InternationalFormatted: phonenumbers.Format(metadata, phonenumbers.INTERNATIONAL), - Version: Version, - }) -} - -func main() { - lambda.Start(parse) -} diff --git a/netlify.toml b/netlify.toml deleted file mode 100644 index ac30089..0000000 --- a/netlify.toml +++ /dev/null @@ -1,7 +0,0 @@ -[build] -command = "make build" -functions = "functions" -publish = "site" - -[build.environment] -GO_IMPORT_PATH = "github.com/nyaruka/phonenumbers" \ No newline at end of file diff --git a/site/index.html b/site/index.html deleted file mode 100644 index 8caf3ff..0000000 --- a/site/index.html +++ /dev/null @@ -1,57 +0,0 @@ - -
-