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

This is My Code

In This is My Code, our lead data scientist outlines code written in Javascript for a NodeJS process used to move data between AWS ElastiCache Redis and S3.

read more

A FreeMarker Converter in C#

One of our engineers walks through step by step how he created a FreeMarker conversion tool in C# to support SparkPost templates.

read more

Why We Hack

A look inside the internal hackathon trend, the cross-functional relationships that hackathons encourage and more reasons why we hack at SparkPost.

read more

Get started and start sending

Try SparkPost and see how easy it is to deliver your app’s email on time and to the inbox.

Try Free

Send this to a friend