We’re trying to write a custom plugin in Golang, but we’re facing some issues during compilation. For starters, the documentation mentions v3.2.2 and v3.2.1, but we’re using a newer version of Tyk gateway (e.g. v4.0.3).
Can someone provide an example go.mod for newer versions of Tyk? Is the documentation out of date ? It seems that even for v3.2.2. the tag resolves to the go-module version ‘v1.9.2-0.20210930081546-bda54b0f790c’, what’s the version we should use for v4.0.3 ?
These are the commands I use for 4.0.3 golang plugins. Be aware of the initial rm -rf command. It may not be what you want but it suits the way I work
rm -rf go.mod go.sum vendor/
go mod edit -replace github.com/jensneuse/graphql-go-tools=github.com/TykTechnologies/graphql-go-tools@0cc35471c1c
go get github.com/TykTechnologies/tyk@6c76e802a29838d058588ff924358706a078d0c5
go mod tidy
go mod vendor
docker container run -v $(pwd):/plugin-source --rm tykio/tyk-plugin-compiler:v4.0.3 plugin.so
I’ve had success with them for simple golang plugins.
Actually I was able to get this to work, using the following version for tyk v4.0.3: github.com/TykTechnologies/tyk v1.9.2-0.20220614105651-6c76e802a298
I’m so sorry, there was a copy and paste error there. I missed the go mod init step
rm -rf go.mod go.sum vendor/
go mod init tyk-plugin
go mod edit -replace github.com/jensneuse/graphql-go-tools=github.com/TykTechnologies/graphql-go-tools@0cc35471c1c
go get github.com/TykTechnologies/tyk@6c76e802a29838d058588ff924358706a078d0c5
go mod tidy
go mod vendor
docker container run -v $(pwd):/plugin-source --rm tykio/tyk-plugin-compiler:v4.0.3 plugin.so
Exactly, thanks for confirming and sharing your script. How did you identify the git commit hash ? (so that in the future we can also support the upcoming versions of Tyk gateway)