Member-only story

How to Build a Pluggable Library in Go

Discover how Go’s buildmode=plugin lets you dynamically extend application functionality and optimize builds by reducing the binary size and avoiding unnecessary recompilation.

Jose Sitanggang
11 min readAug 22, 2024

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. This file can be loaded by another Go program at runtime. It's useful when you want to add new features to your application without rebuilding it. Instead, you can load new features as plugins.

A plugin in Go is a package compiled into a shared object (.so) file. This file can be loaded using the plugin package in Go, which lets you open the plugin, look up symbols (like functions or variables), and use them.

Hands-on Example

To make this a bit more concrete, let’s dive into an example where this feature really shines.

--

--

No responses yet