Build a Scheduled News Reader with Golang, Reddit and SendGrid


Posted on

GoNewsI have too many good things to say about Go. I absolutely love the language. I could write a full article just on how much I love it and why. Instead, I’ll use Go to help you learn more about Go. Very meta.

Luckily, I am not the only person on our Developer Relations team that loves Go. Yamil is a keen Gopher, and has already written a basic Golang wrapper for the SendGrid API. But especially since the engineering team is adopting Go, we need more examples.

As the title states, we will be building a Scheduled News Reader to email us every morning at 6am, with the latest news and headlines from the Golang Sub-Reddit, using SendGrid’s API and Reddit’s API. This is a fun little hack, but also fairly useful, as I myself am keen to keep up to date with what’s happening in the Golang world. How better to find out, than have the headlines delivered to your email inbox every morning to read over breakfast!?

This sample app is quite detailed, so I’ll provide an overview of how it works here, and you can find a walkthrough on GitHub.

Prerequisites

For this hack, we’re going to use Reddit’s API, SendGrid’s API, and our Golang library for said API. You can find the relevant libraries you require below:

Other than those, we will be sticking to the excellent native libs from Go. Of course, you’ll also need a SendGrid account.

Once you’ve done that, use Go Get to install the dependencies above. I.E.

go get github.com/sendgrid/sendgrid-go

The Rest of the Code

With your prerequisites taken care of, the full walk-through will show you how to:

  • Get the latest headlines from the Go sub-reddit
  • Turn the blob of JSON into something human-readable
  • Refactor the code to work for any sub-reddit
  • Use the score to decide which stories to show
  • Turn the stories into a daily email

If you’re down with Go, but not ready to check out this example app, learn why SendGrid chose Golang (and how to convince your company to do the same).


SendGrid Devangelist. London based polyglot hacker, mainly playing with Golang and Ruby. Musical Hacker, Hardware hacker, Hackathon lover, API abuser and NoSQL user.

Robin Johnson on Twitter

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>