Unable to get Go middleware to load

Hi dear support team!

Unfortunately I’m struggling to get a custom Go middleware running.
I’ve been starting with the tutorial/examples here: Loading Custom Go Plugins into Tyk
Concretely I successfully built the “AddFooBarHeader” plugin example within the provided Docker tykio/tyk-plugin-compiler:v5.2.5 (same version as Tyk). Platform is linux-amd64.

Setting everything up and calling the appropriate endpoint, I’ll always get the following messages in the log:
2024-04-11T09:26:15.679792+00:00 control tyk[2041027]: time=“Apr 11 11:26:15” level=debug msg=Started api_id= api_name=varsrest mw=VersionCheck org_id= origin=10.150.21.229 path=/api/v1/some-service ts=2249285175679492189
2024-04-11T09:26:15.679877+00:00 control tyk[2041027]: time=“Apr 11 11:26:15” level=debug msg=Finished api_id= api_name=varsrest code=200 mw=VersionCheck ns=35616 org_id= origin=10.150.21.229 path=/api/v1/some-service
2024-04-11T09:26:15.679905+00:00 control tyk[2041027]: time=“Apr 11 11:26:15” level=debug msg=Started api_id= api_name=varsrest mw=“GoPluginMiddleware: /opt/tyk-gateway/middleware/plugin.so:AddFooBarHeader” org_id= origin=10.150.21.229 path=/api/v1/some-service ts=2249285175679548886
2024-04-11T09:26:15.679928+00:00 control tyk[2041027]: time=“Apr 11 11:26:15” level=debug msg=Finished api_id= api_name=varsrest code=500 error=“Internal Server Error” mw=“GoPluginMiddleware: /opt/tyk-gateway/middleware/plugin.so:AddFooBarHeader” ns=146589 org_id= origin=10.150.21.229 path=/api/v1/some-service

Unfortunately, I do not know how to get further debug output to see what’s concretely going on here.

@hank Hello and welcome to the community :partying_face:

If I recall correctly. 500 errors are usually due to some syntax error within the plugin. It might be best to start with a simple log statement to confirm the plugin is loading correctly and working. Then build up from there.

Hi Olu,
thanks for your quick reply!
The example plugin.go code is already very minimal and is taken from Tyk homepage/tutorials:

package main

import (
“net/http”
)

// AddFooBarHeader adds custom “Foo: Bar” header to the request
func AddFooBarHeader(rw http.ResponseWriter, r *http.Request) {
r.Header.Add(“Foo”, “Bar”)
}

func main() {}

The integration is by the way done like this


“custom_middleware”: {
“pre”: ,
“post_key_auth”: ,
“auth_check”: {},
“post”: [
{
“name”: “AddFooBarHeader”,
“path”: “/opt/tyk-gateway/middleware/plugin_5.2.5_linux_amd64.so”
}
],
“driver”: “goplugin”
},

Hi,

Are you sure that the plugin is called plugin_5.2.5_linux_amd64.so? The compiler would produce a plugin named plugin_v5.2.5_linux_amd64.so by default. Unless it’s been renamed the file name is wrong which would cause a 500 error.

However it’s better to not specify the full name, because that makes upgrading the gateway harder.
Try this instead.

Please see upgrading your tyk gateway for the reasoning behind this naming.

I’ve compiled and tested the source you’ve provided against a 5.2.5 gateway without issues so I’m sure it works

Cheers,
Pete