Essential Go Plugin  Edit on GitHub      File Issue

Defining and using a plugin

package main

import "fmt"

var V int

func F() { fmt.Printf("Hello, number %d\n", V) }

This can be built with:

go build -buildmode=plugin

And then loaded and used from your application:

p, err := plugin.Open("plugin_name.so")
if err != nil {
    panic(err)
}

v, err := p.Lookup("V")
if err != nil {
    panic(err)
}

f, err := p.Lookup("F")
if err != nil {
    panic(err)
}

*v.(*int) = 7
f.(func())() // prints "Hello, number 7"

Example from The State of Go 2017.

Plugin/
Defining and using a plugin
  ↑ ↓ to navigate     ↵ to select     Esc to close