Created
June 30, 2017 10:04
-
-
Save Xinguang/8ca2259f10ce4860f6680082cded19d3 to your computer and use it in GitHub Desktop.
goplugin
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 | |
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