DEV Community

Ido Shamun
Ido Shamun

Posted on

My 2 Cents On Go

Following my post, I decided to take on an action and learn Go.

As everyone told me it was an easy task and since then I have already deployed two Go services to production on Kubernetes.

Here are my thoughts, bare with me and let me know what you think:

Pros

  • Very easy to learn
  • Lightweight (memory & footprint)
  • High performance
  • Implementation is pretty straightforward
  • Typed language

Cons

  • Error handling can be messy
  • Dep (dependency manager) is not as trivial as NPM
  • GOPATH!? Why is everything has to be in the same directory?
  • Imperative programming (just a personal opinion)

Tips

  • Use alpine or even scratch as a base docker image (my docker image is only 10MB)
  • Make sure to use circuit breakers and timeouts for every third party call (external services, database, etc...). My favorite is afex/hystrix-go, I also tried sony/gobreaker but it has some performance overhead.
  • Use uber-go/automaxprocs for automatically setting GOMAXPROCS according to the resources quota of Kubernetes
  • To mock functions declare them as variables
  • I use the builtin net/http router, usually it is more than enough for a simple microservice

Currently I am having fun writing Go and feeling confident with the outcome. I will keep it going for a while and see how it goes 😜

Top comments (18)

Collapse
 
bgadrian profile image
Adrian B.G.

Imperative programming (just a personal opinion)

All languages are imperative now days, I think you wanted to say Procedural Programming?

I personally love procedural programming, I think Go is the perfect mix between a FP and OOP style. You have a bit of everything to solve problems "good enough" in small/medium projects.

Collapse
 
eljayadobe profile image
Eljay-Adobe

"...Go is the perfect mix between a FP and OOP style."

You're killin' me, Smalls!

Collapse
 
bgadrian profile image
Adrian B.G.

I have no idea what you said, but I will put the accent on "I", as in "for me" :))

I can apply patterns from both world, but of course, does not excel at either of them.

Collapse
 
idoshamun profile image
Ido Shamun

PP is a type of imperative programming. I love FP which is obviously a type of declarative programming.
The code looks much more elegant and clean, sometimes it can be harder to read though.

Collapse
 
arschles profile image
Aaron Schlesinger

I love this writeup - really succinct and accurate, IMO (I've been writing Go almost exclusively for 5+ years)

I felt like the GOPATH and the dependency management tools were always a thorn in my side. Recently, they started turning me off of Go TBH, but 1.11 fixed both (others have more detail). And shameless plug: I'm working on a server for Go modules so that you don't have to pull code directly from GitHub if you don't want to - because that's caused problems in the past too.

github.com/gomods/athens

Collapse
 
quii profile image
Chris James

To mock functions declare them as variables

Do you mean having them as global variables? If so, please dont do this.

Use dependency injection for explicit documentation of what your code is using and where.

Collapse
 
idoshamun profile image
Ido Shamun

For a small scale service I find it cumbersome but you are right DI is the better way

Collapse
 
mustardsauce profile image
Jakub N

Being new to golang, my biggest concern is, how do I organize/structure my code. Flat structure for simple application I am currently building seems reasonable, but it still seems weird for me.

Collapse
 
idoshamun profile image
Ido Shamun

I can totally relate to this one! It annoys me as well, not sure how to structure the project

Collapse
 
mustardsauce profile image
Jakub N

I really like the approach suggested in this article: medium.com/@benbjohnson/standard-p..., but don't want to overcomplicate the whole thing.

Collapse
 
rhymes profile image
rhymes

Dep (dependency manager) is not as trivial as NPM
GOPATH!? Why is everything has to be in the same directory?

I hated this, fortunately with go modules is mostly solved

Collapse
 
bgadrian profile image
Adrian B.G.

I am using Go modules and it works good so far.

Collapse
 
idoshamun profile image
Ido Shamun

Unfortunately I haven't heard about go modules, I'll give it a go

Collapse
 
rhymes profile image
rhymes

ahha don't worry, they are a super recent thing. They have been added in Go 1.11

Collapse
 
stephenafamo profile image
Stephen Afam-Osemene

2/4 of your cons are fixed with Go 1.11 which was released late August.

The GOPATH thing and dependency management.
So simple you don't even have to think about it.

Collapse
 
idoshamun profile image
Ido Shamun

That's great to hear!
I am sure the language will evolve and become much better as long as a tech giant as Google backs it

Collapse
 
david_j_eddy profile image
David J Eddy

Your 'Cons' are my thoughts exactly! The requirement for GOPATH still confused me as to why it is that way. As for the error handling, that should get better with the recent release.