Demonstrating use of Go 1.8 plugins
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Demo to showcase Go 1.8 plugins

Download the repo or use go get to get the code locally.



  • Go 1.8 or above
  • Linux (for now)
  • Glide

Go to simple_example for a demo of calling a function exported from a plugin.

Running CPU and Disk Metrics plugin

To run the plugins execute the following commands

go build -buildmode=plugin -o plugins/ plugins/cpu.go
go run main.go

This will execute cpu plugin and display some cpu stats on the console. To display the disk stats (without restarting the main program), execute following commands

go build -buildmode=plugin -o plugins/ plugins/disk.go
curl -X PUT http://localhost:8000/plugins/reload

You should now be able to see disk stats along with cpu stats.

CPU and Disk Metrics plugin

  • plugins directory contains two plugins, namely cpu.go and disk.go
  • main.go defines a MetricPlugin interface
  • Files in the plugins directory should export a struct) that satisfies the MetricPlugin interface
  • Exported variable name follows Title case convention. ex. cpu.go exports Cpu and disk.go exports Disk. If you write a new mem.go, be sure to export Mem from that file.
  • main.go finds all the plugins (i.e. all .so files under plugins directory) and execute them. It also starts a http web server which can be used to reload new plugins.
  • For reloading the new plugins, add the corresponding .go files in plugins directory and build them using go build -buildmode=plugin -o plugin.go command and then use the curl command mentioned above to reload all plugins

Some Go plugin limitations / gotchas

  • Plugins are only supported on linux (for now)
  • Plugin code needs to be compiled with the same version of Go that was used for compiling the main app (for ex. Go 1.9 plugins won't work on Go 1.8 app)
  • Plugin has to be in the main package. Packages not named main are ignored. For more info, run go help buildmode
  • Plugins can't be reloaded (no hot-code swapping). Refer this issue for more details
  • Loading a copy of the already loaded plugin panics. Refer here