Credits to Brett Jordan (https://unsplash.com/photos/LPZy4da9aRo)

Have you ever heard of Redis Keyspace Notifications? Probably most of you already familiar with redis and even use it on daily basis, but do you know we can get “notified” if there is a key change / expiration happen?

What is this Keyspace Notifications?

Long story short, it’s a pubsub mechanism that allows you to listen for data change in redis. Simple usecases that might be beneficial using this feature for example likes, you want to get notified when some keys are expired, you want to monitor changes for a special key, and any other extension use cases you can think of.

If you…


This will be a short writing if you haven’t utilize the power of go routine to make your application process “faster”. In this example, we will do a simple simulation of doing a function that simulate a “slow process” that takes 1 second to finish, and we’re going to call that function several times with different parameter (to simulate different input / processing).

Credits to Ben Harritt (https://unsplash.com/photos/4W92z8cNQ_c)

Synchronous Process

Let’s write the simple function that simulate a process that takes 1 second to finish, kind of look like this.

func DoSomethingHeavy(id int) {  time.Sleep(1 * time.Second)
// you can print the id of…


Credits to alexander ehrenhöfer (https://unsplash.com/photos/yI4pFmN9ges)

Several moments ago, I was wondering if we have multi cron job that are running same binaries, but we need to make sure that each job / task process is being ran only by one instance, is there a way to achieve that. I know this is weird, why do we bother having multiple binaries? just create one for the cron job! It is right though, but wondering about the problem, I was triggered if we could do it with MYSQL, and it can.

Given Problem Statement and Solution

To sum up, here are the challenge

  1. You have multiple binaries that is running a cron…


Usually i wrote something about software engineering / programming, but this one will be different. I would like to share a thing that happened in 2020 that enlightened and hit me differently. This one will be mostly about how you should care about your health and take good care of it while you can.

Credits to Jamie Street (https://unsplash.com/photos/vcn2ndJ5LwE)

Prolog / Background

Last year, in the Q3 of 2020 my father was sick. It was started with some symptoms of limp, sometimes hard to breath, lack of appetite, nausea, and others uncomfortable things (pardon me for not so good english in describing a disease related topic). The point…


Credits to Greyson Joralemon (https://unsplash.com/photos/9IBqihqhuHc)

There are several “fun things” that you need to know, this might help you to prevent going in pitfalls when writing golang program. These includes:

  1. Interface contains nil but not considered as nil
  2. Slice and Map are reference type
  3. Child Go routine and Parent
  4. Don’t use basic type string / int / others for context key

Interface Holding Nil Value, But Not Nil

Look at the simple code below

var i interface{}
var pint *int
i = pint
fmt.Println(pint, pint == nil, i, i == nil)

It will print the output of

<nil> true <nil> false

While pint variable is a nil (a pointer to an int…


Credits to Łukasz Rawa (https://unsplash.com/photos/_4NF4Jppx-c)

Recently I created a simple Golang automatic “retrier” that will do automatic retry on our desired struct method with configurable maximum attempt.

Summarizing the automatic retrier flow there are several things that we need to implement:

  1. We need to create a struct that implements the “retriable” interface, which consist of “Exec() error” method.
  2. Then we can create a new retrier function with object based on the previous struct, configured with our desired maximum attempt and logger if needed (by New command)
  3. Invoke the action to do the execution and automatic retry upon failing the Exec method (by Start() command)

If…


Credits to Tamara Gak (https://unsplash.com/photos/1vZAezBEADw)

Continuing our basic Golang unit testing example, we are going to continue on another step of simple function mocking for unit testing in Go. In here We’re only going cover this two “kind” of function:

  1. Function in your own package
  2. Function imported (from library or stuff) outside of your project

Therefore, we’re not going to “mock” method which belongs to a struct right now. You might ask, why do I need to mock a function? Can we just call the function as is? …


Credits to NeONBRAND (https://unsplash.com/photos/60krlMMeWxU)

In a nutshell basically you need to test the code you write to ensure you’re doing it right. If you have a function that add two numbers, you will expect the result to be sum of those two numbers, by writing the unit test, you make sure that when the function is being ran with the given parameters, it will return the correct / expected result or behavior.

This writing will cover up only the basic of golang unit testing with some example and explanation, more advance and complex unit testing / even mocking a function will be covered in…


Credits to Markus Spiske at https://unsplash.com/photos/Skf7HxARcoc

Have you ever heard of closure before?

Ups different closure…

So, What is Closure in Golang?

By Tour of Go definition, closure can be described as

Go functions may be closures. A closure is a function value that references variables from outside its body. The function may access and assign to the referenced variables; in this sense the function is “bound” to the variables.

I modified the code a bit from the Tour of Go example:


We’re going to create a simple API doc with the help of https://github.com/swaggo/swag library. It supports several golang framework such as gin, echo, fiber, flamingo, net/http, etc. In a nutshell you need to install it first (for generating via CLI), write some comments metadata in your API / handler / controller, generate and done!

Image example from the github documentation

Creating the API

First let us create some simple API using gin framework. We’re initiating an API group of “/api/v1/user” in which consists of two endpoint

  1. Get user detail based on id
  2. Post and create new user based on JSON body sent by request

Aditya Rama

Fellow Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store