4

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

vahdet
  • 6,357
  • 9
  • 51
  • 106
ajeyprasad
  • 41
  • 1
  • 3
  • You get that error for a reason. Try deleting the plugins and rebuilding them. Also make sure that if they use "shared" packages with your main app, they must also match! – icza Nov 22 '18 at 12:15
  • Yes i have shared package i.e., Go-Gin. So what I have to do to make it work? – ajeyprasad Nov 22 '18 at 12:34
  • You must use the same version of the shared packages. E.g. if you get the shared package, you build your plugin, then you update the shared package and you build your main app, that will cause the error you see. Whenever the shared packages change, you must rebuild both the plugins and the main app. – icza Nov 22 '18 at 12:35
  • Shared package is also having same version and rebuilt. But still same problem – ajeyprasad Nov 22 '18 at 12:43
  • Are you by any chance vendoring the packages? A vendored package is not identical to the non-vendored package, even if the source matches exactly. – icza Nov 22 '18 at 12:45
  • github.com/gin-contrib/sse this is the package i'm getting error. I have deleted this package in both machine and go get github.com/gin-contrib/sse and built main and plugin. But no luck. – ajeyprasad Nov 22 '18 at 12:50

1 Answers1

0

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.

liurui
  • 1
  • 3