I am running tyk-gateway version 2.9.2. From log startup :
| time=“Jan 13 13:25:01” level=info msg=“Tyk Gateway started (v2.9.2)” prefix=main
I compile a Go plugin (go source liftet from tyk.io documentation) using :
docker run -v c:/Users/XLA/IdeaProjects/ping-access-token-auth/goSrc:/go/src/plugin-build tykio/tyk-plugin-compiler:v2.9.2 pingaccess.so
But I get an error :
time=“Jan 13 13:25:01” level=error msg=“Could not load Go-plugin” error=“plugin.Open(”/opt/custom/plugin/pingaccess"): plugin was built with a different version of package github.com/TykTechnologies/tyk/regexp" mwPath=“/opt/custom/plugin/pingaccess.so” mwSymbolName=PingAccess
The plugin tested was copied straight from the docs :
package main
import (
"net/http"
"github.com/TykTechnologies/tyk/ctx"
"github.com/TykTechnologies/tyk/headers"
"github.com/TykTechnologies/tyk/user"
)
func getSessionByKey(key string) *user.SessionState {
// here goes our logic to check if passed API key is valid and appropriate key session can be retrieved
// perform auth (only one token "abc" is allowed)
if key != "abc" {
return nil
}
// return session
return &user.SessionState{
OrgID: "default",
Alias: "abc-session",
}
}
func MyPluginAuthCheck(rw http.ResponseWriter, r *http.Request) {
// try to get session by API key
key := r.Header.Get(headers.Authorization)
session := getSessionByKey(key)
if session == nil {
// auth failed, reply with 403
rw.WriteHeader(http.StatusForbidden)
return
}
// auth was successful, add session and key to request's context so other middle-wares can use it
ctx.SetSession(r, session, key, true)
}
func main() {}
The sample does not run either :
_1 | time=“Jan 14 09:01:13” level=info msg=“API bind on custom port:0” prefix=main
tyk-gateway_1 | time=“Jan 14 09:01:14” level=error msg=“Could not load Go-plugin” error=“plugin.Open(”"): realpath failed" mwPath= mwSymbolName=
There is an error in the docker command on the documentation page :
docker run -v pwd:/go/src/plugin-build tyk-plugin-compiler:2.9.0 post`
Is has unpaired ’ and does not produce a “post.so” file as documented. It produces a “post” file.
I use this instead :
docker run -v c:/path/plugin:/go/src/plugin-build tykio/tyk-plugin-compiler:v2.9.2 post.so
tyk-gateway_1 | time=“Jan 17 08:11:51” level=error msg=“Could not load Go-plugin” error=“plugin.Open(”/opt/custom/plugin/pingaccess"): plugin was built with a different version of package github.com/TykTechnologies/tyk/regexp" mwPath=“/opt/custom/plugin/pingaccess.so” mwSymbolName=PingAccess
OK so according to our product team there’s some bug which prevents proper usage of tyk packages. It is planned to be fixed in the next patch release in 2.9.3.
If you want use Go plugin with our docker or official binary, you can’t use Tyk packages.
If you do - you can clone our repo, build it with Tyk and run the binary (you can probably build your own container, but you can’t use our release docker till we fix it)
Hi
Last night I tried v2.9.3 and it worked well with a few of Tyk’s libraries.
There’s also PR in our GitHub tyk-doc repo to clarify the command
Will try to share my repo tonight.