Never miss a beat

Join my newsletter.

The Archives

Using Mongo's ObjectIDs with Go-Graphql

Published: 10/20/2019

I’ve been working on building a Graphql API in Go and recently ran into an issue serializing Mongo’s ObjectIDs. This doesn’t sound like a difficult task, and thankfully it’s not, but it wasn’t super obvious how to go about this. First, we need to identify what an object ID really is. In the official Mongo driver, we can see that there is a type representation for ObjectID. Additionally, there are methods to convert an ObjectID to a hex value and vice-versa. This means that we could maintain two…

Pagination in Scala with Slick

Published: 9/2/2019

Pagination is the idea that a list of content can be broken into separate pages. When I first heard of pagination, the common practice was to use query params to influence which rows of content was loaded by the server. If you clicked the “next” button on the page, it would reload the page with new query params. Fundamentally, pagination hasn’t changed much, but the landscape in which it exists has changed drastically. While some monolithic apps are still built today, the pattern for modern web…

Go's Athens Project

Published: 8/26/2019

I recently got back from Gophercon in San Diego and am still excited about the talk on the Athens Project. For those unaware, the Athens Project is a module proxy for Go! It’s currently in beta, but showing a ton of promise already. Go’s dependency management has changed a lot over the past few years. For simplicity, Go allowed you to simply specify your dependencies in your code as an import. go get would then get all the dependencies that your application needed. This worked, for a while…

A Beginner's Guide to Java Enums

Published: 8/5/2019

An Enum in Java is a special data type that encompasses a set of predefined constants. When setting a variable of that Enum type, you have to use one of the constants that you define for it. A great example is the compass: In the above example, we create a new enum and it’s predefined set of constants. Then we create a variable of that enum type, and assign it to one of the constants. Keep in mind that we can only set our direction to Compass.NORTH , Compass.SOUTH , Compass.EAST , Compass…

Testing a Cobra CLI in Go

Published: 7/18/2019

Go has a fantastic library for writing CLI’s (Command Line Interfaces) called Cobra . I’ve been working on a CLI named Deckard for a few months now. Being new to Go, I had (lazily) shied away from writing tests. However, after thinking about my test plan and doing a little refactoring, I’ve found a great way to handle testing your Cobra CLI application. The idea behind Cobra is that you simply write “Command” functions. These command functions are then called by the Cobra library when it…

How Golang Interfaces Work

Published: 7/8/2019

Interfaces are a tool that allows you to define the behavior of objects and in Golang, interfaces are no different (except that they work on structs instead of “objects”). However, Go has some strange features for interfaces that users from other languages might not expect. Let’s take it slow and start by defining an interface in Go: This fairly simple interface defines what a sandwich is capable of. Not what it looks like, not how it’s composed, but for the purposes of our application it’s all…