Created
February 18, 2017 10:33
-
-
Save ik5/49837c8c98dd8bd6db78476d232e0699 to your computer and use it in GitHub Desktop.
go 1.8 plugins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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