Go custom plugin is not working (response chain)

We are using go custom plugin but it is giving 500 error

http: superfluous response.WriteHeader call from github.com/TykTechnologies/tyk/gateway.(*ReverseProxy).HandleResponse (reverse_proxy.go:1382)

But it is working fine locally using docker we have tyk 5.3.1 and using bundles


import (
	"bytes"
	"io/ioutil"
	"net/http"
)

// MyPluginResponse intercepts response from upstream
func MyPluginResponse(rw http.ResponseWriter, res *http.Response, req *http.Request) {
	// add a header to our response object
	//res.Header.Add("X-Response-Added", "resp-added")

	rw.WriteHeader(http.StatusOK)
	// overwrite our response body
	var buf bytes.Buffer
	buf.Write([]byte(`{"message":"Hi! I'm a response plugin"}`))
	res.Body = ioutil.NopCloser(&buf)

}

func main() {}
{
    "custom_middleware": {
        "response": [
          {
            "name": "MyPluginResponse",
            "require_session": false,
            "raw_body_only": false,
            "path": "MyPluginResponse.so"
          }
        ],
        "driver": "goplugin"
    },
    "file_list": [
      "MyPluginResponse_v5.3.1_linux_amd64.so"
    ]
  }

Thanks,
Shahbaz Ali

We have triggered a hot reload as well because it is helm chart deployment in Openshift environment we don’t know if we need to stop/start the whole pod/container again ?

It is working now, using below commands

docker run -v pwd:/plugin-source -t --workdir /plugin-source --platform=linux/amd64 --entrypoint go --rm tykio/tyk-plugin-compiler:v5.3.1 mod init tyk-plugin

docker run --rm -v pwd:/plugin-source --platform=linux/amd64 tykio/tyk-plugin-compiler:v5.3.1 CustomPluginResponse.so $(date +%s%N)

docker run --rm -v pwd:/cloudplugin --platform=linux/amd64 --entrypoint “/bin/sh” -it -w “/cloudplugin” docker.tyk.io/tyk-gateway/tyk-gateway:v5.3.1 -c ‘/opt/tyk-gateway/tyk bundle build --output bundle.zip -y’

Great to hear you were able to self resolve the issue