Skip to content

Instantly share code, notes, and snippets.

@ik5
Created February 18, 2017 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ik5/49837c8c98dd8bd6db78476d232e0699 to your computer and use it in GitHub Desktop.
Save ik5/49837c8c98dd8bd6db78476d232e0699 to your computer and use it in GitHub Desktop.
go 1.8 plugins
package main
import "C"
import (
"fmt"
"plugin"
)
func main() {
p, err := plugin.Open("./plugins.so")
if err != nil {
panic(err)
}
a, err := p.Lookup("A")
if err != nil {
panic(err)
}
print, err := p.Lookup("Print")
if err != nil {
panic(err)
}
*a.(*int) = 42
print.(func())()
fmt.Printf("a = %d\n", *a.(*int))
}
// stored on it's own location, not part of the same location of main.go
package main
import "fmt"
var A int
func Print() {
fmt.Println("Here is a print ", A)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment