Error handling in concurrent programs in Golang
Error handling in concurrent programs in Go consists of little more work than if err != nil { return err } because the return value doesn’t reach intended receiver (for example in parent function where function was fired as a goroutine using go keyword). Just as we use channel for sending resulting data, we must…
Context package in Golang
Go has a package named context in its standard library. It’s responsibilities are cancelations and carrying request-scoped data (but that doesn’t mean it’s only used in HTTP handlers). I’ve learned it in two parts. For a long time I used it only for storing request-scoped data in HTTP middlewares, but recently I’ve learned the rest…
Testing concurrent code in Golang
I wrote a package which tracks certain hashtags on twitter and part of the package is adding and removing hashtag from list of hashtags. Plan is that this can be done from different goroutines hence tracking/untracking is done by putting hashtag in channels. It looks like this: var ( trackChan = make(chan string) untrackChan =…
Exporting data as CSV file from web apps (with Golang)
While you can certainly export data from javascript with two different ways, they both aren’t good solutions. First one doesn’t allow you to name the downloaded file (it’s just download), second is only supported in Chrome, Firefox and latest version of Microsoft Edge (by the time of writing this post). So the only acceptable option…
Goroutines don’t panic if channel they write to is gone
Couple of months ago I wrote an article about error handling in concurrent Go programs. One concern I had about it was if other goroutines would panic if some goroutine produces an error value which causes return from function when the channel is iterated with range construct. So I made another program that mimics scenario.…