Skip to main content


Showing posts with the label Golang

Playing with Hooks in Gorm #GolangDev

Hello everyone, I would like to share some tricks in gorm, the Idea of this tricks is to execute a command or code statement in the middle of an ORM operation, if you ever know about trigger in the query language, then hooks is just kinda like that. Hooks could execute statement in some events such as: beforeCreate, beforeUpdate, afterCreate,  and afterUpdate. those event is similar as a trigger,  when the trigger is executed in DBMS layer, hooks are executed in the application layer.
In my real case, my current company has different convention of naming database column, so when I try to implement ORM, a lot of columns such as created_at, updated_at and deleted_at can't be generated automatically. also if you have a custom UUID you could pass the value UUID generator into hooks before the insert is executed. for more detail let's jump into code :

# ExplanationAbove code containing model struct, and several methods from gorm to serve model, TableName method used to define table n…

How Strict is Golang? #GolangDev

Hello everyone, in this occasion I would like to share about the strictness of golang. what kind of strict? let see below.

Golang is the functional programming that really have concern about performance, giving limitation to prevent overuse memory is the big deal. for example, golang has a variative type of data such as int, string, boolean, float, array etc. I wonder that you are thinking about "what kind of strictness that is? its totally similar other language", YES. but golang have specification in numeric type of data such as int have int8, int16, int32, int64. golang also have uint8, uint8, uint32 and uint64 which is its really strict you know. the following number after type of data is stand for the length. Obviously you could use the largest type of data for all the variables, but you know it could overwhelming if you put int64 in "is_valid" variable right? joking :D. golang really care about performance, because each length of variable is matters for memo…

Variadic Function vs Slice Param Function in Golang #GolangDev

Hello everyone, good to see you again. I am gonna share about a simple thing in fundamental Golang, this article inspired by a QnA in a website and I think I will tell the answer more flexible and wider in my personal tutorial, so this is about differentiation between Variadic Function and Slice Param in Function.

# Variadic Function
Variadic function is an unique code, this code is enable us to passing a infinite params in one function, we know that we need to put parameters in function we need to put the space in there, for example : function(param1 int, param2 string), golang absolutely doing that thing too, seems like the other languages, but Variadic function is a something new, you could put many value in function and sapparated by comma, you maybe thing about passing array in parameters but this is something different, you dont need to put parenteses when you call the function, it just like you put regular parameters but have an infinite numbers.  for example :

we could see tha…

Create MVC Pattern Using Echo Framework #GolangDev

Hi, Back again. today I am gonna share about Go Language, yes it is a new programming language that really fast growing this day, so many startup using it, especially in indonesia, there is a Gojek, Dana, Tiket and many more. Go Lang is a programming language found by google engineer, this language is a multi paradigm language, you could use it as functional programming or treat it like an OOP bases.

Echo is an framework that use Golang as a main language, to use a fast and reliable backend/web apps, as you know Golang has a really fast performance than other language, one of the reason is because its compiled not interpreted, so the Echo claim that its 10x faster. insane right ? Actually I didn't test the performance yet, but yeah for newbie like me in golang its not the main thing that you must understand, so the thing that we should know is how we actually can do with Golang. 
I am person with MVC bases, before jump to golang, I have experience with Laravel, you know its typica…