Reputation: 41
VM1 and VM2 both have go version 1.11.1.
My Scenario:
VM1:
main.go
package main
func startGin() *gin.Engine {
gin.SetMode(gin.ReleaseMode)
router := gin.New()
v1:= router.Group("/v1")
all_plugins, err := filepath.Glob("plugins/*.so")
if err != nil {
panic(err)
}
for _, filename := range all_plugins {
p, err := plugin.Open(filename)
if err != nil {
panic(err)
}
handler, err := p.Lookup("Handler")
if err != nil {
panic(err)
}
v1.GET("/sample", handler.(func() gin.HandlerFunc)())
}
return router
}
func main() {
router := startGin()
server := &http.Server{Handler: router}
ln, err := net.Listen("tcp4", ":8080")
if err != nil {
log.Error.Printf("error during startup", err)
}
server.Serve(tcpKeepAliveListener{ln.(*net.TCPListener)})
}
go build main.go
VM2:
plugin.go
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
func Handler() gin.HandlerFunc {
return func(c *gin.Context) {
c.JSON(200, "Success")
}
}
go build -buildmode=plugin plugin.go
Getting Error "plugin was built with a different version of package
Upvotes: 4
Views: 3824
Reputation: 1
I have the similar issue. I find even with same version of Golang and same package, they may not work together and give out the message of “plugin was built with a different version of package”. This is because the build machine of the main app and the build machine of the plugin have different environment variable "GOPATH" which will impact the hash to identify the package.
Upvotes: 0