Go FuncCloser pattern

I’ve run quite a few times into this issue lately. I have an io.Reader which wraps another io.Reader but does not offer a way to close the inner io.Reader. One instance of this issue is with the bufio.Reader type. The function below opens the given file, peeks at the first 512 bytes to try to detect the mime type, and then returns an io.ReadCloser to read and then close the file....

August 15, 2023

Go Quirks

I’ve recently started working with Go on a full time basis. It’s a fun language to use, and it comes with a rich standard library. Shipping a production ready HTTP server in the standard library is no small feat. It’s not free from issues and quirks though. In this post, I’ll discuss some of the issues and quirks I’ve encountered in my journey with Go. I’ve deliberately chosen to not talk about often raised issues such as the lack of generics and the err !...

March 28, 2020