Quick way to combine io.Reader and io.Closer

There are many interesting tools in Golang’s standard library to wrap io.Reader instance such as io.LimitedReader or cipher.StreamReader. But when wrapping a io.ReadCloser instance, the Close method is hidden. Here’s a quick code snippet to combine wrapped io.Reader and the original io.Closer through an inline struct to rebuild the io.Closer interface. Code var rc io.ReadCloser = struct { io.Reader io.Closer }{ Reader: r, Closer: c, } What it is about? The io....

January 22, 2023

Throttling Pool

In my last post I presented few techniques useful for limiting simultaneous operations in Go. Such throttlers are indeed a very neat tools to keep our resources under control. However we can be extended that idea to even better tool for resource control when we mix throttlers with object pools. Object pools in go Even though golang has a very efficient memory management system, there are some cases where we would like to manage the memory by ourselves....

November 22, 2022

Throttling in Go

Go language makes a good job at making hard things simple. It compiles the code so that it runs fast, it comes with garbage collector so we don’t have to deal with memory management, it has lightweight goroutines and we don’t have to think a lot about concurrency limits. And in majority of cases all those language constructs combined with sane defaults will be good enough. Just like writing a web server....

October 7, 2022

Multi-CPU Github Actions with Go

When we think about CPU architecture usually there’s one leader that comes to our mind - the famous x86-64 one. It is the main player on our desktops and on the server side. Even more recent generation of game consoles switched to that architecture from some more exotic ones. But there are alternatives. Some are pretty well known such as the ARM one that took over the mobile market (and slowly enters the desktop world with Apple M1 laptops)....

July 19, 2022