Tag go

Mocking system time in tests

Introduction Recently I was working on my personal project and I encountered a situation where I was calling time.Now() to get the current system time. I was working on a function to calculate someone’s age from a birthday, I needed this function to display it in my app. I did not want another field in my database with someone’s age, since in my opinion this calculation from the birthday is pretty trivial.

Clean code using decorators

Introduction In this blogpost I’m going to explain how to keep your code clean using decorators. By applying decorators the open close principle is maintained, code becomes easier to extend and easier to adjust. Background According to wikipedia the decorator pattern is a design pattern that allows behaviour to be added to an individual object, without affecting the behavior of other objects from the same class. In go this means that we extend the functionality of a function or method(s) of a struct without changing the original functions or method(s).

Clean http handlers in Go

Introduction For this blog post we are going to take a look at the http.HandlerFunc type and how we can improve it to make more elegant and clean handlers. Following the idioms of Go and staying compatible with the standard library. Handlers In Go A Handler is a type which responds to an HTTP request. type Handler interface { ServeHTTP(http.ResponseWriter, *http.Request) } Any struct implementing the ServeHTTP method from the interface can be used to handle http requests.

Build your own ASCII github issue table in Go!

Introduction In this blogpost I’m going to show you how you can create your own github issue table for inside your terminal. We will be covering some cool features and the implementation. Code can be found here: Github repo The looks of the application Programming What we want to achieve with the application is that we can specify a github repository url somehow and display x amount of issues in a pretty printed table.

Tutorial: Identicon generator in Go

Introduction In this tutorial we are going to build a simple identicon generator in Go. The source code can be found here: Github repo. But what exactly is an Identicon? I think most of you are familiar with the standard logo you get when creating a new account on Github. Example: What you see here is a visual representation of a hash value. What this basically means is that a input is hashed with a hashing algorithm(md5, sha256) and the output is used to generate a image.