🐔 What happened with my project on the Rinha de Backend challenge

rooster fight

I participated in the Rinha de backend (pt-BR) or “Backend Rooster Fight” in English challenge and I was super excited to see the results of my super hacky and performant solution.

The results were scheduled to be published at 21:00 BRT (2 AM CEST my local time). So I stayed up til later that night grabbed popcorn, and waited for the results.

Well, I wish I hadn’t waited…

Continue reading...

🐉 got: Embracing my lazyness with my custom git CLI

The eyes of Drogon

got is a CLI written in Go, created on top of the git CLI, to make my life easier by shortening some commands I use daily.

Because it’s built on top of git, all git commands will also work just fine and I don’t need to keep switching between got and git!

If I want to clean up my local dead branches I can got rmb instead of git branch | grep -v "main" | xargs git branch -D (you can call me lazy. I accept that 😅).

xckd 1319

xkcd Automation.

Continue reading...

📂 Go: Importig a CSV to PostgreSQL

contents of a CSV file with each column in a different color

If you are using Go ad PostgreSQL, and need to performa a bulk import a CSV, it’s most likely you will find the COPY protocol is the feature that suits you better. In that direction, you will find examples using pgx CopyFrom that relies on the native protocol, and it’s fairly easy to use. However, depending how it’s used you can have an exponencial increase of memory consumption of your application making it unreliable and more expensive to run.

Continue reading...

🔢 Go: Where is the decimal type?

Gopher side-eye

Go doesn’t have a primitive decimal type for arbitrary-precision fixed-point decimal numbers. Yes, you read it right. Therefore, if you need to deal with fixed-point precision there are two main options:

  • Use an external package like decimal, which introduces the decimal type. However, the current version (1.3.1), can “only” represent numbers with a maximum of 2^31 digits after the decimal point.
  • Use int64 to store and deal with these numbers. For e.g. given you need 6 precision digits, therefore 79.23, 23.00, and 54.123456, become respectively 79230000, 23000000, and 54123456.

There is an open proposal to add decimal float types (IEEE 754-2008) in the std lib. However, for now, it’s just a proposal being discussed, without guarantee it will be ever added.

🧠 Go resources for beginners

Gopher side-eye

Below a living list of compiled links for whoever is learning Go.

Official docs

  • Effective Go - https://go.dev/doc/effective_go
    • A document that gives tips for writing clear, idiomatic Go code. A must-read for any new Go programmer. It augments the tour and the language specification, both of which should be read first.
  • Go Code Review Comments https://github.com/golang/go/wiki/CodeReviewComment

    • This page collects common comments made during reviews of Go code, so that a single detailed explanation can be referred to by shorthands. This is a laundry list of common mistakes, not a comprehensive style guide. You can view this as a supplement to Effective Go.

Continue reading...