A month with Go

A month with Go

I've started a new project, a personal project that even when you don't know exactly how far you can go, how many active users you expect to have in a near future, or even if you are going to finish the project, you always want to think on the best scenario for your app and the best architecture to support this scenario.

I have enough experience working with Python and Java. Starting a Rest API with any of these languages is just a matter of hours (or minutes) to get the minimal code up & running. Django for Python, or Play Framework for Java (between other good web framework), both are some of the most famous web framework with a lot of support for both.

Java can be faster for being a strongly typed language, vs python with its dynamically typed architecture, more flexible and its particular syntax.


Before going with any of these languages I took some time to do some research and compare both of them with Golang, this new programming language created by Google and designed for web services mainly.

GoLang removes a lot of features that are not related to web applications, some of these missing features can be part of a longer discussion, mainly for classes and interfaces not available for this language (obviously with a strong argument behind).

Let's start with the performance, as I've mentioned before, Go has been designed for web applications and the performance is excellent for this, it's a compiled language based on C, but it has improvements for the memory management, garbage collector and more. It overpasses Python and NodeJS performance with higher request per seconds (lot of benchmarks on the web that you can check to compare performance for different frameworks available for languages mentioned above), specially when we are talking about a compiled language, also the performance is better than Java with some of its best web framework, including vert.x with a great performance for Java.

Syntax is much simpler than C, more readable, and it contains some features that are very useful for variables declaration, implicit assignments, and more.

Lot of good things around this language, and that was the moment when I said "Ok, let's give a chance to this language", I knew I was chosen one of the best web framework at the moment, with great performance, meaning a fast backend and great latency for my app.

First I was planning to grab an Udemy course, but then I decided to go through the official documentation and tutorial and everything was really smooth.

Then I was planning to use an SQL DB, Postgres specifically, and I wanted a good library to make things easier and faster, and I know there are a lot of libraries available, but I found Gorm (ORM for Go) a very useful library, easy to integrate, easy to use, it can create your DB structure automatically based on your models, you declare models easily and run DB operation with a single line.

It was a matter of a week to learn the basics of Go, and be able to get my Rest API up and running with Gorm and Postgres, implementing three different collections in my Rest API, around 16 endpoints for CRUDs operations and more.

Cons

There's something that needs more research on my side, but sounds like you need a specific structure for your external libraries, and even for your project, I'm not able to run code out of the ~/go/src folder, where ~/go is the GO_HOME folder.

I'm able to change this folder, but my code must be stored inside src/ folder, the same folder used for downloaded libraries.

Conclusion

It has been a month aGO when I've started this odyssey, and now I'm very happy with the language and the results I've got in a very short period of time. How clear is the code, the structure you can use to get things organized, how easy is to deal with middlewares, routers, JSON objects, logger, and more. Even compiling time is really fast, and the memory footprint is insignificant for a small API like this.


Share Tweet Send
0 Comments
Loading...

Related Articles