-
-
Save KentaKudo/9e6f2acc2fded682622bb6eaf1bd366e to your computer and use it in GitHub Desktop.
Try out go plugin package
This file contains hidden or 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 ( | |
"fmt" | |
) | |
// F is to be loaded and called from main(). | |
func F() { | |
fmt.Println(`This is a function in "a.go"`) | |
} |
This file contains hidden or 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 "fmt" | |
// F is to be loaded and called from main(). | |
func F() { | |
fmt.Println(`This is a function "b.go"`) | |
} |
This file contains hidden or 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 ( | |
"fmt" | |
"os" | |
"plugin" | |
) | |
func main() { | |
if len(os.Args) < 2 { | |
fmt.Println(help()) | |
os.Exit(1) | |
} | |
p, err := plugin.Open(os.Args[1] + ".so") | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "Unexpected command: %s", err) | |
os.Exit(1) | |
} | |
f, err := p.Lookup("F") | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "Function F not found: %s", err) | |
os.Exit(1) | |
} | |
f.(func())() | |
} | |
func help() string { | |
return "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.