Practical Design Pattern in Go: Functional Options

The Functional Options Pattern is a design pattern for creating objects with flexible configurations by using functions as arguments to modify the default behavior. In my opinion, this pattern can be considered a Builder Pattern with a functional style: instead of chaining methods, we compose functions to configure the object. This pattern is widely used in Go, which might be the reason it is not explained in most design pattern books....

October 30, 2023 · 7 min · 1428 words · Jose Sitanggang

Practical Design Pattern in Go: Adapter

The Adapter Pattern is a structural design pattern that allows objects with incompatible interfaces to collaborate1. Let me clarify something: an interface does not always mean the type Something interface, but in this context, it is more likely to refer to the contract between types. ATTENTION: I am not sponsored by Refactoring.Guru, but I definitely recommend that you buy the “DESIGN PATTERNS” book. It covers all known design patterns in depth and provides easy and simple explanations....

October 29, 2023 · 7 min · 1482 words · Jose Sitanggang

Namespace in Go

Actually, Go doesn’t have a namespace feature like C++ and C# does. However, we can achieve the same effect in Go. How? Let’s examine the problem for a moment to ensure that we are on the same page. I have a package called httpkit. This package contains many helpers for developing REST APIs. package httpkit // MuxOption is an option for customizing the ServeMux. type MuxOption func(mux *ServeMux) // NewServeMux creates a new ServeMux with given options....

October 29, 2023 · 6 min · 1239 words · Jose Sitanggang