Today I Learned About Golang
banner
til-about-golang.bsky.social
Today I Learned About Golang
@til-about-golang.bsky.social
Interesting bits and pieces, gotchas, things that are nice to know about the Go programming language.
The current default for GOAMD64 is v1 and for GOARM64 is v8.0
April 1, 2025 at 9:42 PM
Nil channels are useful, when working with a select case statement with multiple cases receiving from different channels. Setting a channel to nil will block the channel and disable the case for future checks. This means that this case will not be executed anymore.

youtu.be/t9bEg2A4jsw?...
justforfunc #26: why are there nil channels in Go?
YouTube video by justforfunc: Programming in Go
youtu.be
February 24, 2025 at 5:02 PM
Furthermore a special go package "time/tzdata" can be imported to provide the necessary timezone data.
February 13, 2025 at 8:16 PM
If there is a low amount of defer statements the amount of which is known at compile time, they can be inlined in the function they are called in.

More on this topic: victoriametrics.com/blog/defer-i...
Golang Defer: From Basic To Traps
The defer statement actually has 3 types: open-coded defer, heap-allocated defer, and stack-allocated. Each one has different performance and different scenarios where they’re best used, which is good...
victoriametrics.com
December 20, 2024 at 10:26 PM
If the amount is known at compile time, we have stack-allocated defers. If it is not, like in case of defer statements in a for loop, _defer gets allocated on the heap.
December 20, 2024 at 10:24 PM
A further "chaining" of pointers is possible, meaning there can be variables of type ***string, ****int and so on.
December 12, 2024 at 6:58 PM
This is due to the fact, that maps grow dynamically in size. The capacity that is provided during initialization is only used as a hint for the map's size.
November 29, 2024 at 9:37 PM
An interesting corollary is, that, declaring a channel with var c chan(int) vs initializing a channel with make(chan int) bears a huge difference. The first, without further code, will result in a nil value.
November 25, 2024 at 7:48 PM