Hi Team.
I have been trying to test about go custom plugins in my local environment following these documents
-
Golang plugins
But it didn’t work well and seems out-dated for current version (4.3.1).
My environment
- local PC: macOs monterey (go version darwin/arm64)
- tyk-pro-demo : v.4.3.1
- using docker
Server: Docker Desktop 4.16.0 (95345)
Engine:
Version: 20.10.22
API version: 1.41 (minimum version 1.12)
Go version: go1.18.9
Git commit: 42c8b31
Built: Thu Dec 15 22:25:43 2022
OS/Arch: linux/arm64
Experimental: false
I got this error after configuring like this
API Raw definition
"custom_middleware": {
"pre": [
{
"name": "Test",
"path": "/plugin-source/go_v4.3.1_linux_arm64.so",
"require_session": false,
"raw_body_only": false
}
],
"post": [],
"post_key_auth": [],
"auth_check": {
"name": "",
"path": "",
"require_session": false,
"raw_body_only": false
},
"response": [],
"driver": "goplugin",
"id_extractor": {
"extract_from": "",
"extract_with": "",
"extractor_config": {}
}
},
Docker log
time="Jan 20 02:58:20" level=error msg="Unsupported extension '.so' (/plugin-source/go_v4.3.1_linux_arm64.so)" prefix=jsvm
time="Jan 20 02:58:20" level=info msg="Checking security policy: Open" api_id=028b3ec2b8414ea741f8574e702f6cc6 api_name=Agoda org_id=63c9f86f15fbf50001cc6f39
time="Jan 20 02:58:20" level=error msg="Could not load Go-plugin" error="plugin.Open("/plugin-source/go_v4.3.1_linux_arm64.so"): /plugin-source/go_v4.3.1_linux_arm64.so: invalid ELF header" mwPath="/plugin-source/go_v4.3.1_linux_arm64.so" mwSymbolName=Test
Go file
package main
import "fmt"
func Test() {
fmt.Println("**********Test Function Called************")
}
func init() {
fmt.Println("**********Custom Plugin Test Initialize************")
}
func main() {
}
p.s i cannot build with this command, because it didn’t match amd64/arm64 well in my local PC.
docker run --rm -v `pwd`:/plugin-source tykio/tyk-plugin-compiler:v4.3.1 gogogo.so v1 linux arm64
so i used this command
go build -buildmode=plugin -o go_v4.3.1_linux_arm64.so
Is there anything i am missing?
Please let me know why
Thanks.