Skip to content

Instantly share code, notes, and snippets.

@Xinguang
Created June 30, 2017 10:04
Show Gist options
  • Save Xinguang/8ca2259f10ce4860f6680082cded19d3 to your computer and use it in GitHub Desktop.
Save Xinguang/8ca2259f10ce4860f6680082cded19d3 to your computer and use it in GitHub Desktop.
goplugin
package main
func Add(x, y int) int {
return x + y
}
func Subtract(x, y int) int {
return x - y
}
// docker run -it --rm -v $(pwd):/go/src/github.com/xinguang/test golang:alpine sh
// cd /go/src/github.com/xinguang/test
// go build -buildmode=plugin -o aplugin.so golangfilename.go
// #apk add --update gcc libc-dev
// how to use
// package main
//
// import (
// "fmt"
// "plugin"
// )
//
// func main() {
// p, _ := plugin.Open("./aplugin.so")
// add, _ := p.Lookup("Add")
// sub, _ := p.Lookup("Subtract")
//
// sum := add.(func(int, int) int)(11, 2)
// fmt.Println(sum)
// subt := sub.(func(int, int) int)(11, 2)
// fmt.Println(subt)
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment