Everybody loves plugins. Well, not everybody, but they can offer many advantages. Arguably the biggest ones are modularization of your program and making it easy to extend it. We are working on an open source project in Go and needed these benefits, so I opted for a plugin architecture. But how?
Go offers a way to create and load plugins.
Unfortunately it imposes a lot of
technical limitations.
Yet even disregarding those, your functionality is spread over several binary files.
We decided to create a small tool to solve this: spluggy
.
spluggy
is a code generation tool which helps you can define static plugins (i.e. at compile time.)
These plugins are then built into a single executable.
It provides a way to have modularity and extensibility without managing multiple binaries.
spluggy
is written with the lazy busy developer in mind. You don’t need to maintain an explicit list of your plugins.
You only have to define them as sub-packages within the same package.
As long as they expose a common function, spluggy will discover your plugins and expose them to external packages.
spluggy
is available on Github.
The repository has an example demonstrating how to use spluggy
in your project.