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.
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.
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.