SparkPost Client Library for Go Released!

Dave Gray
Jan. 22, 2016 by Dave Gray

Go SparkPost Library Released

Our Go client library is now publicly available!

We’ve been using it internally for various projects during development and now it’s time to go public. If you’re not familiar, “Go from Google” AKA Golang is a newer programming language, as these things, ahem, go. It’s been used to build a variety of publicly-available software including Docker and the Let’s Encrypt certificate authority. For a browser-based introduction to Go, check out A Tour of Go.

Go is statically typed and compiled, unlike most of the other languages that we have client libraries for. This makes the code a bit more verbose, and can make parsing JSON a bit frustrating at first. One of the goals of this library is to minimize that frustration during the “getting started with SparkPost and Go” phase.

So how do you use the SparkPost client library for Go? Once your Go workspace is set up, you can run:

This will download the client library code so it’s ready to import:

Now we’ll initialize the library with connection and authentication settings, pulling our API key from the environment:

With the setup and config out of the way, what can you do today with our Go client library?

We have full support for the Transmissions, Templates, and Recipient Lists endpoints, which is enough to support most sending use cases. Templates and Recipient Lists can be pre-created, which speeds things up if you’ll be reusing the same ones a lot – they can be specified by ID. If you won’t be reusing, or if you’d simply prefer to be more dynamic, Transmissions can also be sent using an inline Template and/or Recipient List, meaning that they’re included as part of the Transmissions call.

Here’s an example of what sending a transmission looks like:

Using the snippets above, you’re ready to start sending through SparkPost with Go. If you’ve been paying close attention, you’ve noticed that combining these code snippets with your API key gives you a way to send test messages. You could even build a CLI that allows you to send tests specifying the sender, recipient, and other fields as flags.

So what’s next for the Go client library?

Watch this space for more code examples and more advanced usage. We plan to use this library in several of our upcoming projects, including a sample application demonstrating how to easily parse event data out-of-band. We’re also working on support for Message Events, which lets you search through the last couple day’s worth of event data generated in your account.

What else will you build with our client libraries? We’re curious to see, so drop us a line and let us know.


Dev Survival Guide Blog Footer

Related Content

How to Use Microservices to Build an API That Lasts

Learn some successful strategies incorporating microservices that we use to continuously evolve our API through rapid growth and adoption.

read more

How to Use SparkPost in Go

One of our developers shares a quick and easy tutorial illustrating how to use SparkPost and Go to send emails - actual gophers not included.

read more

Community Spotlight: Maximize Learning with Megafind

Learn how winners of the Cal Hacks 4.0 hackathon are revolutionizing the concept of taking lecture notes and studying with their application, Megafind.

read more

Start sending email in minutes!

The world’s most powerful email delivery solution is now yours in a developer-friendly, quick to set up cloud service. Open a SparkPost account today and get started for free.

Get Started

Send this to a friend