GO & Plugins

Kaushal M

Software Engineer at Red Hat

GlusterFS Co-Maintainer




  • What is a plugin
  • How are plugins generally implemented
  • Doing it in Go

What is A plugin?

A software component that adds or extends features to an existing computer program without modifying the original program

Benefits of plugins

  • Easily add new features
  • Allow third-party developers to add/extend features
  • Flexibility of shipping and asynchronous updates

Implementing a plugin system

  • Host process
    • Define a plugin interface
      • (optionally) a plugin request interface
    • Define a location to drop plugins into
    • Load plugins and execute them

Implementing a plugin SYSTEM

  • Runtime loading and execution of plugins
    • Requires support for dynamic loading
    • C/C++ - dlfcn.h, dlopen(), dlsym()
    • Java - ServiceLoader, ClassLoader
    • Python - __import__(), importlib.import_module()
    • Go - nil (at least for now)

Implementing a plugin SYSTEM

  • Plugin

    • Implement the interface, generally as a shared library
    • Drop into the plugin location

Plugins in GO

  • Standalone programs and IPC 
  • Embedded scripting languages
  • package plugin

Plugins in GO - Standalone/IPC

  • Actual executable applications
  • Plugins started as sub-processes
  • Use IPC to communicate
  • Simple to implement

Plugins in GO - Standalone/IPC

  • + Use Go as the plugin language
    • Any language that can understand the IPC mechanism
  • + Possibly more secure
    • Host process can't be compromised
    • Plugin failures don't affect the host process
  • - Performance

Plugins in GO - Standalone/IPC

Plugins in GO - Embedded Language

  • Plugins are scripts
  • Host application embeds a scripting language interpreter
  • Use interpreter methods to communicate
  • Relatively more complex

Plugins in GO - Embedded Language

  • + Easier to develop plugins
  • - Cannot use Go as the plugin language
  • - Relatively less secure
    • Can crash host
  • - Debuggability
  • ~ Performance

Plugins in GO - Embedded Language

Plugins in GO - package plugin



GO & Plugins

By Kaushal Madappa


GO & Plugins

Go Devroom @ FOSDEM'16

More from Kaushal Madappa