Skip to main content

Posts

Showing posts with the label Backend

Automatic API Documentation Swagger in Golang #GolangDev

pixabay.com In this article, I'll explain how to generate an API blueprint instantly using SwagGo in Golang. API blueprint is a document that contains a bunch of API endpoints, its slickly same as documentation but less description, it's allow another programmer to read and see all the available endpoint and try it out with sandbox feature. Swagger is one of the most used API blueprints right now, it's available in free but limited usage. if you wanna use the free credit, you need to understand YAML notation, you can read the example notation in swagger official documentation. but again, it's really hard and takes an expensive time to arranges all the notation to achieve a good API blueprint. fortunately, there are tools in Golang that allow us to generate the YAML notation and automatically generate the blueprint page with only using markup notation, and it's FREE unlimited for self-host, insane right? SwagGo tools are available here , the documentation is very cl...

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 ...

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 d...