Plugin

Other topics

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.

Contributors

Topic Id: 9150

Example Ids: 28409

This site is not affiliated with any of the contributors.