3 ms·
> Building Go packages as a shared library Yes, please! We have a few potential Go projects which are blocked by the inability to separate Go code into plugins
by lobster_johnson 12y ago
> Building Go packages as a shared library
Yes, please! We have a few potential Go projects which are blocked by the inability to separate Go code into plugins.
I have toyed with the idea of forking child processes and implementing plugins via pipe I/O, but that's a very unfriendly API interface, and I don't feel very inspired. (Go isn't that great at POSIX stuff like forking, either.)
- _stephan 12y agoWhy do the plugins have to be dynamically loaded? Would a source-based plugin/package system be an alternative?
- lobster_johnson 12y agoConsider a data processing app. It calls little data-processing modules written in Go. You want to open-source it because it's general-purpose and reusable; but you don't want to open-source all your in-house, proprietary data-processing components, too; they're not of use to anyone but yourself, or they may be something you can't open-source for other reasons. That means the core project cannot list its plugins as dependencies. You will instead want to be able to load plugins from a configuration file. (The problem is actually equally awkward in languages that have package systems, such as Node and Ruby. In Ruby, for example, a program can only see gems declared in the Gemfile; same problem with npm-shrinkwrap.json.) I suppose you could set up a special build system where plugins are expected to be installed into a certain folder so that they're statically built in, with some kind of hook so that they're registered into the core. That's the Nginx approach. I'm not a big fan, especially since this method of building things need to be reinvented for each app that needs a plugin system. You could, of course, invert the relationship and make this system a library: To set it up with your plugins, you write a small program that runs the system's main entrypoint with a list of plugins. But that just makes it harder to configure, build, use and deploy.