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....

August 27, 2024 · 14 min · 2876 words · Jose Sitanggang

Go Concurrency Patterns: Pipeline

In a previous article, we explored the Generator pattern, which allows us to compute values lazily in Go. Now, we’re diving into another concurrency pattern: the Pipeline. This pattern enables us to process data step-by-step through a series of operators. If you’re familiar with Java Streams, which process data by passing each value through a set of filters, we’ll be taking a similar approach but leveraging Go’s concurrency features....

August 26, 2024 · 12 min · 2416 words · Jose Sitanggang

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’ll cover in this article is similar to the yield keyword in Python and the generator function in JavaScript....

August 25, 2024 · 8 min · 1594 words · Jose Sitanggang

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’s official documentation. The documentation was pretty straightforward, so I decided to try it out, and now I want to share what I’ve learned. What is go buildmode=plugin? The go buildmode=plugin option allows you to compile Go code into a shared object file....

August 22, 2024 · 12 min · 2519 words · Jose Sitanggang

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’re on the same page, let’s clone this repository to use as our base code....

April 15, 2024 · 10 min · 2078 words · Jose Sitanggang