123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package main
- import (
- "log"
- "plugin"
- "time"
- "dev.hexasoftware.com/stdio/plugintest/native/plugbase"
- )
- func main() {
- for {
- callPlugin()
- <-time.After(2 * time.Second) // wait 2 sec
- }
- }
- func callPlugin() {
- defer func() {
- if r := recover(); r != nil {
- log.Println("Recover")
- }
- }()
- var err error
- //Reopen plugin
- plug, err := plugin.Open("plugins/bin/plugin1.so")
- panicIfErr(err)
- pluginfo, err := plug.Lookup("Info")
- panicIfErr(err)
- log.Println("s:", pluginfo.(*plugbase.PlugInfo).Author)
- fn, err := plug.Lookup("ExportedFunc")
- panicIfErr(err)
- fn.(func())()
- }
- func panicIfErr(err error) {
- if err != nil {
- panic(err)
- }
- }
|