SmartyStreets Go SDK

If you want to access our US Street Address API or US ZIP Code API from an application written in the Go programming language, the SmartyStreets Go SDK can make it a lot easier. Our Go SDK includes ready-made data structures and takes care of all the gritty, low-level HTTP intricacies for you.

Contents

  1. Requirements
  2. How to Get It
    1. The 'go' Command
    2. Downloading the Source Code
  3. How to Use It
    1. Documentation
    2. Examples
  4. API Reference Material

Requirements

  1. Decide to build a software project using the Go programming language.
  2. Download and install Go version 1.7+.
  3. Setup a Go workspace.
  4. Build enough of the project to realize that you now need an address verification component.
  5. Wisely conclude that you don't want to build your own address verification component.
  6. Realize that SmartyStreets has already created an address verification component.
  7. Congratulations! You are now ready to use the SmartyStreets Go SDK.

How to Get It

The 'go' Command

The easiest way to get your giddy hands on this goodness is by using the go command at the terminal.

go get -t -u github.com/smartystreets/smartystreets-go-sdk

You can then import the SDK packages in your Go project. (See the examples below.)

Downloading the Source Code

You can download the source code from github.

How to Use It

Documentation

If you're new to the Go community, do yourself a favor and learn about godoc and godoc.org. The Go SDK makes use of godoc conventions for documenting source code, which you can read by downloading the source code or perusing the auto-generated documentation for each package in the SDK:

Examples

Here's an example of how to use the Go SDK:

Verifying US Street Addresses

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/smartystreets/smartystreets-go-sdk/us-street-api"
	"github.com/smartystreets/smartystreets-go-sdk/wireup"
)

func main() {
	log.SetFlags(log.Ltime)

	client := wireup.NewClientBuilder().
		WithSecretKeyCredential(os.Getenv("SMARTY_AUTH_ID"), os.Getenv("SMARTY_AUTH_TOKEN")).
		//WithDebugHTTPOutput(). // uncomment this line to see detailed HTTP request/response information.
		BuildUSStreetAPIClient()

	lookup1 := &street.Lookup{
		Street:        "1 Rosedale",
		City:          "Baltimore",
		State:         "MD",
		MaxCandidates: 10, // This input produces more than one candidate!
	}
	lookup2 := &street.Lookup{
		Street: "1600 Pennsylvania Avenue",
		City:   "Washington",
		State:  "DC",
	}
	lookup3 := &street.Lookup{
		Street: "1600 Amphitheatre Parkway Mountain View, CA 94043",
	}

	batch := street.NewBatch()
	batch.Append(lookup1)
	batch.Append(lookup2)
	batch.Append(lookup3)

	if err := client.SendBatch(batch); err != nil {
		log.Fatal("Error sending batch:", err)
	}

	for i, input := range batch.Records() {
		fmt.Println("Results for input:", i)
		fmt.Println()
		for j, candidate := range input.Results {
			fmt.Println("\t Candidate:", j)
			fmt.Println("\t", candidate.DeliveryLine1)
			fmt.Println("\t", candidate.LastLine)
			fmt.Println()
		}
	}
}

Here's the output from a successful run of the above example code:

						
Results for input: 0

  Candidate: 0
  1 N Rosedale St
  Baltimore MD 21229-3737

  Candidate: 1
  1 S Rosedale St
  Baltimore MD 21229-3739

Results for input: 1

  Candidate: 0
  1600 Pennsylvania Ave SE
  Washington DC 20003-3228

Results for input: 2

  Candidate: 0
  1600 Amphitheatre Pkwy
  Mountain View CA 94043-1351


						
					

Product Features Demo Pricing Help Company Documentation Articles Contact Customers Legal Stuff