Defining and using a plugin

suggest change
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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents