Go plugin (tyk v4.1) Could not load Go-plugin

Hi,

I can’t make Go plugin to work, it’s load is broken at startup. I followed the docs, but I might have missed something.

e8b6854e2edc4ecab1afc9f445942/my_plugin_v4.1.0_linux_amd64.so"): /opt/tyk-gateway/middleware/bundles/b6de8b6854e2edc4ecab1afc9f445942/apigw_plugin_v4.1.0_linux_amd64.so: cannot open shared object file: No such file or directory mwPath=/opt/tyk-gateway/middleware/bundles/b6de8b6854e2edc4ecab1afc9f445942/apigw_plugin_v4.1.0_linux_amd64.so mwSymbolName=MyPreHook

Plugin init with the ‘git show-ref tags/v4.1.0’ hash

Compiled with the tyk-plugin-compiler

  • docker run --rm -v ${MY_ROOT}/go_plugin:/plugin-source tykio/tyk-plugin-compiler:4.1.0 my_plugin

The library is actually there (bundle downloader works fine)

  • docker exec -ti tykgw4 /bin/bash -c ‘ls -l middleware/bundles/b6de8b6854e2edc4ecab1afc9f445942’
-rw-r--r-- 1 root root 7922080 Sep 26 21:24 apigw_plugin_v4_1_0_linux_amd64.so
-rw-r--r-- 1 root root     481 Sep 26 21:24 manifest.json

Even though by default it’s access is 0600, it ‘go+r’ does not help.

the plugin is a simple

func MyPreHook(rw http.ResponseWriter, req *http.Request) {
   req.Header.Add("X-test-pre", "pre_hook_AAA")
}

The manifest is also just

 "file_list": [ "apigw_plugin_v4_1_0_linux_amd64.so" ],
    "custom_middleware": {
     "pre": [ {
        "name": "MyPreHook",
        "path": "apigw_plugin_v4.1.0_linux_amd64.so"
      } ],
      "driver": "goplugin"
    }

Can anyone show a working Go plugin with v4.x or hint what could be missing?

Hi @szalabala ,

Welcome to Tyk Community and thank you for posting your question here. I used your plugin and manifest and it seems that I can properly run this plugin in my environment using v4.1.0.
Make sure that you set these required configurations in your tyk.conf.

My plugin looks like this:

package main

import (

"net/http"

"log"

)

func MyPreHook(rw http.ResponseWriter, r *http.Request) {

r.Header.Add("X-test-pre", "pre_hook_AAA")

log.Println("THISISPLUGINLOG")

}

func main() {}

As for building the plugin, these are the steps I made for v4.1.0:

My manifest looks like this:

{
"file_list": [ "plugin_v4.1.0_linux_amd64.so" ],
"custom_middleware": {
 "pre": [ {
    "name": "MyPreHook",
    "path": "plugin_v4.1.0_linux_amd64.so"
  } ],
  "driver": "goplugin"
}
}

Then here’s how I build it in the gateway:
/opt/tyk-gateway/tyk bundle build -y --output="build2.zip"

I also made sure that my API definition got this: "custom_middleware_bundle": "build2.zip",

Note: If you are using docker to run TYK in Macbook M1, the error cannot open shared object file: No such file or directory might also appear and you need to set this variable before installing TYK to force docker to use amd64:
export DOCKER_DEFAULT_PLATFORM=linux/amd64

Hope this helps!

1 Like

It works, thanks a lot!

Especially for answering questions that I missed, namely that I’m running on MacBook M1. After reinstall Tyk … now the plugins work nicely!

2 Likes

I had this exact problem. Interestingly, forcing docker to use amd64 as suggested didn’t work. I had to pull the amd64 image and specify the platform when running the gateway image even though I had inspected the image manifest and confirmed that it amd64 is supported. Pulling another image worked.

This is on Tyk v4.2.2

docker pull --platform=linux/amd64 [tyk-image]

docker run --platform=linux/amd64 [tyk-image]
1 Like