Live data from Hacker News

Go in Production – Lessons Learned

tdom.dev

1–10 of 109 posts

Re: Go in Production – Lessons Learned

#3
I wouldn't describe this as good lessons for using Go in production, I would describe this as "opinions I came to after building my first real Go web project."

1. You probably do NOT need a framework

Use the default Go HTTP libraries. For the other functionality that you'll need, use libraries. If you throw in with frameworks like Labstack Echo, you're forever coupled to the incredibly specific and one-note behavior of the framework you choose. The dependencies you choose should be light, with their most attractive aspect being the interfaces they provide. I point most strongly to go-kit as an EXCELLENT set of libraries for writing HTTP services. Their Log package is a small example of what I look for in quality libraries.

2. You NEED a good code structure

You need to be structuring your code, yes. But you should NOT be leaning on the conventional directory structure to give meaning. You will need to read more of other peoples code than you will need to write your own code, and other people will not be following your code structure. Much more useful is to get good tools and practices reading code. Go, unlike other languages (e.g. C#), is meant to be readable and understandable without a heavy IDE there to help resolve elaborate indirection and overloaded imports. If you have the code on your disk and can use Grep, you'll do fine. If you're using an editor which supports language servers like Gopls, you'll be able to fly through the codebases.

3. Pick a DB driver wisely, and the wisest choice for SQL driver is database/sql

SQLx is not database/sql, which is a real problem when most all the ecosystem is built around database/sql. The only real pain point people have with database/sql is the scanning, which is why other people have built libraries to help with this: https://github.com/kisielk/sqlstruct

Probably just use database/sql.

4. Docker

Most all of this advice is fine.

Basically, I recommend sticking to the more lightweight and more standard implementations, as they have the abstractions you'll need to the long haul. Though if you're just trying to get a thing going ASAP and it has to be Go, do what you gotta do with the code that catches you're fancy.

Re: Go in Production – Lessons Learned

#4
The more you get to know Go's stdlib the less and less youll think a web framework is necessary.

Youll find that utilizing http Round Tripper along with the Handler interface in the http library will make middleware easy.

Youll eventually dig into filepath and path methods for extracting path parameters from url paths.

And logging and recovery will be a concept youll need to extend outside of just http and into the rest of your application.

I totally advise new comers to use a web framework, but in the long run, you probably wont want too.

Re: Go in Production – Lessons Learned

#6
post #4

The more you get to know Go's stdlib the less and less youll think a web framework is necessary. Youll find that utilizing http Round Tripper along with the Handler interface in the http library will make middleware easy. Youll eventually dig into filepath and path methods for extracting path parameters from url paths. And logging and recovery will be a concept youll need to extend outside of just http and into the r…

What path to this enlightenment would you recommend to one who has cut his teeth and delivered many projects (over many years) in Rails/Django?

Re: Go in Production – Lessons Learned

#8
post #6
post #4

The more you get to know Go's stdlib the less and less youll think a web framework is necessary. Youll find that utilizing http Round Tripper along with the Handler interface in the http library will make middleware easy. Youll eventually dig into filepath and path methods for extracting path parameters from url paths. And logging and recovery will be a concept youll need to extend outside of just http and into the r…

What path to this enlightenment would you recommend to one who has cut his teeth and delivered many projects (over many years) in Rails/Django?

This is a side effect of go’s lack of meta programming to be honest. So much magic that is possible in rails/django/etc is just not possible in golang.

This leads to go web frameworks being sort of semi-hard mountainous turds of code generation. You’ll want to stick to stdlib after sifting through them and deciding they aren’t worth it.

Re: Go in Production – Lessons Learned

#10
post #4

The more you get to know Go's stdlib the less and less youll think a web framework is necessary. Youll find that utilizing http Round Tripper along with the Handler interface in the http library will make middleware easy. Youll eventually dig into filepath and path methods for extracting path parameters from url paths. And logging and recovery will be a concept youll need to extend outside of just http and into the r…

[deleted]
Post reply on HN