Skip to content

Instantly share code, notes, and snippets.

@cp-i-pc
Created November 30, 2018 14:58
Show Gist options
  • Select an option

  • Save cp-i-pc/ce79f032086684afce73e7e73f179278 to your computer and use it in GitHub Desktop.

Select an option

Save cp-i-pc/ce79f032086684afce73e7e73f179278 to your computer and use it in GitHub Desktop.

Minimum recurring issue gist

v2ray/v2ray-core#1442

go build -o ./plugin.so -buildmode=plugin ./plugin.go
go test ./

#output
hi there!
--- FAIL: TestTypeAssert2 (0.00s)
panic: interface conversion: plugin.Symbol is func() string, not main.PluginFunc [recovered]
... ...
package main
func Plugin() string {
return "hi there!"
}
package main
import (
"fmt"
"plugin"
"testing"
)
type PluginFunc func() string
var pluginSymbol plugin.Symbol
func TestTypeAssert1(t *testing.T) {
f := pluginSymbol.(func() string)
fmt.Println(PluginFunc(f)())
}
func TestTypeAssert2(t *testing.T) {
f := pluginSymbol.(PluginFunc)
fmt.Println(f())
}
func init() {
p, _ := plugin.Open("plugin.so")
pluginSymbol, _ = p.Lookup("Plugin")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment