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