Zip Code validation using the USPS API in Go.
If you already have the USERID, creating the client is simple:
client := usps.New("USERID")
client := usps.NewClient("USERID", usps.WithHTTPClient(&http.Client{
Transport: &urlfetch.Transport{Context: appengine.NewContext(r)},
}))
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))
}
go get -v -u github.com/dlutton/usps
This software is created under Apache v2 License. For the full license text, please see License.md