Skip to main content

Posts

Showing posts with the label Golang

Switching Validator Language in Echo Framework #GolangDev

pixabay.com Hello everyone, for right now I wanna share how to switch language validator in the echo framework. this framework actually using the go-playground library as its default validator. so if you wanna use a validator and have a limited example to read, just go to this repository, you can find more examples about its usability. don't forget to hit the stars, it's very useful.  In my case, I have an issue that my current project needs me to translate the validator error message from English into Bahasa Indonesia. there is an example in the go-playground validator repository that we can switch the validator message into another language. Thank god, there is an Indonesian developer who contributes that repository to translate the message into Bahasa Indonesia.  after implementing code from go-playground documentation, then I got next issue, the thing is we need to implement the current docs into the echo framework version, which is not suitable at all, you will find an e

Playing with Hooks in Gorm #GolangDev

Pixabay 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 : # Explanation Above code containing model struct, and several methods from gorm to serve model, TableName method used to de

How Strict is Golang? #GolangDev

pixabay.com 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 v

Variadic Function vs Slice Param Function in Golang #GolangDev

pixabay.com 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 ex

Create MVC Pattern Using Echo Framework #GolangDev

pixabay.com 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 La