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 evenscratch
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)
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.
"...Go is the perfect mix between a FP and OOP style."
You're killin' me, Smalls!
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.
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.
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
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.
For a small scale service I find it cumbersome but you are right DI is the better way
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.
I can totally relate to this one! It annoys me as well, not sure how to structure the project
I really like the approach suggested in this article: medium.com/@benbjohnson/standard-p..., but don't want to overcomplicate the whole thing.
I hated this, fortunately with go modules is mostly solved
Go get(s) modules
rhymes
I am using Go modules and it works good so far.
Unfortunately I haven't heard about go modules, I'll give it a go
ahha don't worry, they are a super recent thing. They have been added in Go 1.11
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.
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
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.