Smarty Go SDK
Let's dive into the Go client for Smarty’s address verification, geocoding, autocomplete, and data enrichment APIs.
The Smarty Go SDK lets you integrate address intelligence into your Go applications with minimal boilerplate. Whether you’re validating millions of addresses, enriching them with precise geocodes, or powering an autocomplete form, the SDK gives you a clear, Go-native way to call every Smarty API.
Contents
- Installation
- Authentication
- Create an API client
- Create and send lookups
- Examine results
- More examples
Installation
Install the SDK (from the root directory of your Go module):
go get github.com/smartystreets/smartystreets-go-sdk
Update your module
go mod tidy
Import packages:
import (
street "github.com/smartystreets/smartystreets-go-sdk/us-street-api"
"github.com/smartystreets/smartystreets-go-sdk/wireup"
)
Authentication
Smarty offers two kinds of credentials depending on where your code runs:
- Server-side (backend, CLI, batch jobs)
Use Auth ID + Auth Token (a Secret Key pair). - Client-side (browser, front-end, public UI)
Use Auth Web + Auth Referer (a Website Key pair restricted by domain).
You can find all keys in your Smarty account under:
Account → API Keys.
We recommend storing your credentials in environment variables for security:
export SMARTY_AUTH_ID="your-auth-id"
export SMARTY_AUTH_TOKEN="your-auth-token"
export SMARTY_AUTH_WEB="your-auth-web"
export SMARTY_AUTH_REFERER="your-auth-referer"
For details on authentication, and embedded vs. secret keys, see our authentication documentation.
Create an API client
The SDK offers different client builders for each API. These come from the wireup package – Smarty’s
helper layer.
Server-side client
Here’s an example for us-street-api:
client := wireup.BuildUSStreetAPIClient(
wireup.SecretKeyCredential(
os.Getenv("SMARTY_AUTH_ID"),
os.Getenv("SMARTY_AUTH_TOKEN")
),
)
Browser/Frontend client
Here’s an example for international-autocomplete-api:
client := wireup.BuildInternationalAutocompleteAPIClient(
wireup.WebsiteKeyCredential(
os.Getenv("SMARTY_AUTH_WEB"),
os.Getenv("SMARTY_AUTH_REFERER")
),
)
You can find a full list of API clients and options here.
Create and send lookups
Create lookups based on the addresses you want to validate. Here’s an example for us-street-api:
addresses := []string{
"1600 Pennsylvania Avenue Washington, DC",
"1600 Amphitheatre Parkway Mountain View, CA 94043",
}
batch := street.NewBatch()
for _, address := range addresses {
lookup := &street.Lookup {
Street: address,
}
batch.Append(lookup)
}
Use the client you created earlier to send the batch:
if err := client.SendBatch(batch); err != nil {
log.Fatal("Error sending batch:", err)
}
Examine results
Review the results provided by the API:
for i, lookup := range batch.Records() {
fmt.Println("Results for lookup:", i)
fmt.Println()
for j, candidate := range lookup.Results {
fmt.Println(" Candidate:", j)
fmt.Println(" Input ID: ", candidate.InputID)
fmt.Println(" ", candidate.DeliveryLine1)
fmt.Println(" ", candidate.LastLine)
fmt.Println()
}
}
More examples
- US Street API
- US Autocomplete Pro API
- US Enrichment API
- US Extract API
- US Reverse Geocoding API
- US ZIP Code API
- International Autocomplete API
- International Street API
All Go SDK examples can be found on our github here.