Skip to content
/ usps Public

A Go client to validate ZIP Codes using the USPS API

License

Notifications You must be signed in to change notification settings

dlutton/usps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 

Repository files navigation

usps

CircleCI GoDoc Go Report Card

Zip Code validation using the USPS API in Go.

Examples

Authentication

If you already have the USERID, creating the client is simple:

client := usps.New("USERID")

Google App Engine settings

client := usps.NewClient("USERID", usps.WithHTTPClient(&http.Client{
	Transport: &urlfetch.Transport{Context: appengine.NewContext(r)},
}))

Full Example

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

About

A Go client to validate ZIP Codes using the USPS API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages