github gitlab twitter email
One hour of joy (with go)
Feb 7, 2018
3 minutes read

I’ve always been a big fan of simplicity and objectiveness of C language. It doesn’t take too long to get know the basics of the language and be ready to take-off and start build some powerfull.

That being said, here comes Go, to me it has the same pro points that C has plus a good std library where you can always find a good start point to solve a problem.

Nowadays I’m still programming in Go just for small pet projects, and today I give myself one hour to see what I can build using Go.

Just to put things in context. In my daily development routine in one hour I can’t do many things, because the tooling that I work(Proprietary ERP programming language, SQL, PL/SQL) generally push me back to get things done. So for me accomplish something in one hour is really great.

So, let’s get it started

Yesterday I was looking at awesome-go repo and I thought:

It would be good to know how many stars/watchers each one repo has

Of course those metrics doesn’t guarantee repo’s code quality but for me it’s a good start to look around, and even better, it’s a “good itch to start scratching” in one hour.

And after 1 hour of coding I accomplished:

  • Look for a GitHub API that give me such info about a repo
  • Based on GitHub URL, extract username and repo name
  • Call the API with username and repo and receiving a json
  • Parse the json the get the specific info that I want(stars and watchers)

Because I’ve never worked parsing json files before I ended up spending more time on that. And it was very good because after reading a blog post about this subject I learned that:

Unmarshal will decode only the fields that it can find in the destination type… This behavior is particularly useful when you wish to pick only a few specific fields out of a large JSON blob. It also means that any unexported fields in the destination struct will be unaffected by Unmarshal. (https://blog.golang.org/json-and-go)

Github API sends a big json so I just need 2 fields(3 because a end up using fork counter) and my struct was in a very slim fit.


Yes, I know it’s few features to get it done in one hour, but considering that I’m new on the language, I felt a great joy to be able to do only this, but in the end get it done.

Nevertheless to finish up my initial idea a need starting doing more serious Go code, that I probably will keep doing it on this one hour recipe, let’s see.


Tags: go golang development


Back to posts