-
Homemade CLI Tools
2021-12-13
Go is great! We all know that. I spend most of my coding time on the back-end of the services we build. For many years, before I moved to Go, I used to create my tools as a combinations of various scripting languages - not excluding PHP! Most of it was run by Bash that was executed as a cron job, systemd service or manually as a one-shot executable. I must say, Bash is not as bad as many seem to think.…
-
Embedding Types to Reuse Code with Less Noise
2020-04-30
My previous post was about one of the concurrency patterns that can be achieved with go. I immediately got some feedback on it, and this is where I will address one of them. You have seen the code reimplementing sync.WaitGroup to have a semaphore in it. type WaitGroup interface { Add(delta int) Done() Wait() } type SemaphoredWaitGroup struct { sem chan bool wg sync.WaitGroup } func (s *SemaphoredWaitGroup) Add(delta int) { s.…
-
Semaphored Wait Group
2020-04-29
One of the first things you might like to try when starting your journey with Go are the concurrency patterns. You will probably start using goroutines to run things “in the background”, and you will also get to know channels that allow for safe communication between the sub-processes. When you’ll want to spawn many goroutines, you will surely get to know WaitGroups to wait for them to finish. There will also be the defer statement which helps you to not forget to clean up after a function has finished running (and remember, deferred calls are executed in reverse order).…