Go Concurrency Patterns: Fan-Out and Fan-In
In our previous articles, we explored the Generator and Pipeline patterns, which are ideal for scenarios where a single consumer processes a stream of data. These patterns are powerful, but they can be limited in situations where you want to fully leverage the capabilities of modern multi-core processors or need to handle I/O-bound tasks more efficiently. To achieve this, we can extend our approach to distribute workloads across multiple consumers....
Go Concurrency Patterns: Pipeline
In a previous article, we explored the Generator pattern, which allows us to compute values lazily in Go. Now, we鈥檙e diving into another concurrency pattern: the Pipeline. This pattern enables us to process data step-by-step through a series of operators. If you鈥檙e familiar with Java Streams, which process data by passing each value through a set of filters, we鈥檒l be taking a similar approach but leveraging Go鈥檚 concurrency features....
Go Concurrency Patterns: Generator
The generator pattern is a mechanism for producing values on demand, meaning values are generated incrementally and only when the consumer requests them. This pattern allows for infinite sequences or large datasets to be produced one element at a time, optimizing memory usage and enabling lazy evaluation. The generator pattern we鈥檒l cover in this article is similar to the yield keyword in Python and the generator function in JavaScript....
How to Build a Pluggable Library in Go
While exploring Envoy Proxy, I got intrigued by how users can write custom code as plugins and load those implementations at runtime. This curiosity led me down a rabbit hole of research, where I stumbled upon the buildmode=plugin option in Go鈥檚 official documentation. The documentation was pretty straightforward, so I decided to try it out, and now I want to share what I鈥檝e learned. What is go buildmode=plugin? The go buildmode=plugin option allows you to compile Go code into a shared object file....
How to Test HTTP Outbound in Go Using Just the Standard Library
The Go standard library is rich and powerful, but we often find ourselves needing third-party libraries to test HTTP outbound. Similar to testing an HTTP handler with the httptest package, we can also test HTTP outbound either with httptest or by extending the http.RoundTripper package. This article will demonstrate how to test HTTP outbound in Go. Prepare the Playground To ensure we鈥檙e on the same page, let鈥檚 clone this repository to use as our base code....