https://github.com/dlutton/usps
A Go client to validate ZIP Codes using the USPS API
https://github.com/dlutton/usps
appengine-go go
Last synced: 11 months ago
JSON representation
A Go client to validate ZIP Codes using the USPS API
- Host: GitHub
- URL: https://github.com/dlutton/usps
- Owner: dlutton
- License: apache-2.0
- Created: 2016-12-21T20:20:51.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-16T00:06:15.000Z (almost 8 years ago)
- Last Synced: 2025-02-19T22:43:02.967Z (11 months ago)
- Topics: appengine-go, go
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# usps
[](https://circleci.com/gh/dlutton/usps)
[](https://godoc.org/github.com/dlutton/usps)
[](https://goreportcard.com/report/github.com/dlutton/usps)
Zip Code validation using the USPS API in Go.
## Examples
### Authentication
If you already have the USERID, creating the client is simple:
```go
client := usps.New("USERID")
```
### Google App Engine settings
```go
client := usps.NewClient("USERID", usps.WithHTTPClient(&http.Client{
Transport: &urlfetch.Transport{Context: appengine.NewContext(r)},
}))
```
### Full Example
```go
package main
import (
"encoding/json"
"log"
"github.com/dlutton/usps"
)
func main() {
client := usps.NewClient("USERID")
results, err := client.ValidateZip("91362")
if err != nil {
if apiErr, ok := err.(*usps.APIError); ok {
log.Fatalf("number: %s, source: %s; %s", apiErr.Number, apiErr.Source, apiErr.Description)
}
log.Fatal(err)
}
output, err := json.Marshal(results)
if err != nil {
log.Fatal(err)
}
log.Print(string(output))
}
```
### Development
```
go get -v -u github.com/dlutton/usps
```
### License
This software is created under Apache v2 License. For the full license text, please see License.md