Zombie Gopher, by Ashley McNamara

Hacktoberfest: Part 3

Sean Prashad
Open Source @ Seneca
4 min readOct 21, 2018

--

The finish line is in sight!

With exactly 10 days until Halloween and the conclusion of Hacktoberfest, the hunt is on to stock up on both candy and bugs. With the former taken care for my household, it’s up to me to help with more PR’s:

Check out your status at https://hacktoberfest.digitalocean.com/stats/

Finding a Project

Luckily the hunt for bugs has been much more pleasant this year. Similar to how I found my first bug back in Part 1, I returned to Google with a search term of Hacktoberfest Golang:

One website in particular caught my attention — https://golanglibs.com. Golanglibs is a website that aggregates Go projects in one spot, allowing you to sort by different categories or even view trending projects:

Check out golanglibs.com/top for projects written in Go!

Skimming through the list of popular projects attracted my attention to one I had seen before — Hugo:

Hugo is a static website generator that is known for its speed. I was actually interested in using Hugo for this very blog many moons ago, but was unsuccessful. This time around, contributing to Hugo would let me see a different side of it— the cogs and gears on the inside — rather than the shiny product I saw as an end-user the first time.

Choosing a Feature

Skimming through the open issues for Hugo, I came across #5040 which was related to a function that I had seen before — json.MarshalIndent.

If you’re unfamiliar with what JSON is, let’s run through it very quickly:

JSON stands for JavaScript Object Notation — essentially it is a syntax for storing and exchanging data that is human readable and lightweight.

An example of JSON data representing me would look something like:

{
"firstName": "Sean",
"lastName": "Prashad",
"isAlive": true,
"girlfriend": false
}

Go’s json package boasts functions for working with JSON. There are two methods there that are of importance to us — json.Marshal and json.MarshalIndent.

json.Marshal converts an interface (think of this like a struct, map, array etc) into its equivalent JSON, while json.MarshalIndent does the same but returns the JSON pretty-printed. Essentially, this means that the JSON will be formatted in a way that is much easier for humans to read. Check out the difference below between the two:

Using json.Marshal:

{"firstName":"Sean","lastName":"Prashad","isAlive":true,"girlfriend":false}

Using json.MarshalIndent:

{
"firstName": "Sean",
"lastName": "Prashad",
"isAlive": true,
"girlfriend": false
}

Interested in interacting with a code snippet? See it on Go Playground here:

Playground snippet available at play.golang.org/p/IDVVk0v2zbH

Submitting a Fix

Reading up on the docs for json.MarshalIndent informed me that there are two extra arguments for this function — a prefix for every line (which we don’t need) and the number of spaces to indent by. After putting in a sensible default of two spaces for the latter (and also updating tests and documentation), my PR is now awaiting a review:

Final Thoughts

Hacktoberfest has been much more fulfilling my second time around for a number of reasons. My course schedule this semester isn’t as jam packed as it was a year ago, I have a handful of experience navigating my way through projects, and I know another t-shirt is on it’s way for more signatures… hopefully before December 🤞🏽🎄🎅🏽

Cheers,

Sean 👨🏽‍💻

Update

My goodness! 30 minutes after I tweeted about this blog post, one of the core maintainers of Hugo liked and retweeted my tweet then reviewed and MERGED my PR!!! 😵😁

Update 2

Over 12 hours later and almost 4,000 people have seen my original tweet 🙀

--

--