Image for post
Image for post
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…


Image for post
Image for post
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 for post
Image for post
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


Image for post
Image for post
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 for post
Image for post
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 for post
Image for post
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…


Image for post
Image for post
Image credits to Héctor Martínez at https://unsplash.com/photos/Hs-Tt4fBX3M

For those of you who haven’t heard, bulk processing in a nutshell can be described more or less of a small multiple processes that is being ran at one single process rather than individually. In this writing, I’m about to show you one simple case in which bulk query to database can enhance performance compared to doing several queries one after another.

There are a few process in this example that we will run through:

  1. Create postgres DB instance
  2. Create users table, and seed some data into the table(100 data)
  3. Create a simple Golang program. In the program we will…


Image for post
Image for post
Image referenced from https://www.elastic.co/blog/elastic-apm-6-5-0-released

Monitoring your application performance is an important subject that must be put in mind when we have our application running in Production. This kind of monitoring helps us to be aware if there is a slow down or performance issue within our system. Without any performance monitoring, it is hard for us to pin point which process takes longer to finish.

There are a lot of APM services out there, but let us try one open source elastic APM with golang this time. This writing will be focus on:

  • Setting up easy APM server on localhost with default configuration
  • Writing…


Image for post
Image for post
Random picture from Tokopedia 10th Anniversary in my album

I had my wonderful time working at Tokopedia for three years starting at 2017 until 2020. Started as a Software Engineer, then Senior SE, and ended up as a Software Engineer Lead taught me a lot of lesson and experience. I met with a lot of great people, friends, and great leaders that directly or indirectly shaped me of who I am right now. As I’m currently starting new Journey in different place and culture, here are some precious highlight that I learned in Tokopedia as an Engineer.

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