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


Credits to Markus Spiske (https://unsplash.com/photos/SH98nuc1-Xc)

If you’re having a public endpoint, securing it is a must and cannot be considered as nice to have. I would like to share several ways to secure your API Endpoint (Golang will be used for this example), and in this writing we won’t be discussing about any encryption related topic for simplicity. There are some ways to secure your API endpoint using these methods:

  1. Sanitize any input in your API to prevent malicious script
  2. Consider limiting your exposed parameter to prevent resource abuse
  3. Only allow trusted source
  4. Implement rate limiter

1.) Sanitize Input


Image credits to CHUTTERSNAP (https://unsplash.com/photos/xewrfLD8emE)

What on earth is this writting? This tutorial will demonstrate a simple golang API for uploading file to Google Cloud Storage. GCS (Google Cloud Storage) can be used for uploading your image, files, assets, basically any file with the benefits of


Image credits to Guillaume Jaillet (https://unsplash.com/photos/Nl-GCtizDHg)

Some of you might already heard about a lot of caching out there, Redis and Memcached probably the common things when we’re talking about caching. However, in this writing I would like to show you a comparison of a simple API performance, in which the data is being stored on database (postgres), redis, and go-cache.

Background Please…

Redis as stated in the official website documentation (https://redis.io/).

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker. Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs…

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