I need to add a function called "New." Doing this returns an interface.
func New() interface{}{ return &Config{}}
After that, I'll create a func. In Go programming language, figure out the request and response handlers for the processing lifecycle. I'll make a func called "Access," which gets the requests and responds.
With Func (conf Config) Access(kong *pdk.PDK) type, I'm getting the key parameter from the URL, and I need the parameter in the config file. For example, apiKey := conf.Apikey. If there’s an error, the system will log it.
x := make(map[string][]string)
x["Content-Type"] = append(x["Content-Type"],"application/json")
if apiKey != key { kong.Response.Exit(403,"Youu have no correct key", x)
}}
### ***Docker File: Create a Builder Image and Copy***
In the Docker file, I created a builder image and copied my local files into it.
FROM kong/go-plugin-tool:2.0.4-alpine-latest AS builder
RUN mkdir -p /tmp/key-checker/
COPY . /tmp/key-checker/
RUN cd /tmp/key-checker/ && \
go get github.com/Kong/go-pdk && \
go mod init kong-go-plugin && \
go get -d -v github.com/Kong/go-pluginserver && \
go build github.com/Kong/go-pluginserver && \
go build -buildmode plugin key-checker.go
After that, I got the files to build an image into the Kong image.
FROM kong:2.0.4-alpine
RUN mkdir /tmp/go-plugins
COPY --from=builder /tmp/key-checker/go-pluginserver /usr/local/bin/go-pluginserver
COPY --from=builder /tmp/key-checker/key-checker.so /tmp/go-plugins
COPY config.yml /tmp/config.yml
USER root
RUN chmod -R 777 /tmp
RUN /usr/local/bin/go-pluginserver -version && \
cd /tmp/go-plugins && \
/usr/local/bin/go-pluginserver -dump-plugin-info key-checker
USER kong
In this case, I'll do this by running Docker images using the default path. Therefore, I don’t need an extra parameter. When you build a Kong plugin, you should use the same compiler version, configuration, environment variables, etc., with the Go plugin server. To guarantee consistency, I've built my custom Go plugin server in the same Docker image.
After that, copy the built files into the Kong image.
### ***Run Related Comments on the Terminal***
My plugin is ready to run as a container.
docker build -t kong-demo .
After that, I’m going to run the image as a container.
I’m defining some paths, such as plugins directory or configuration files directory. Now we can call our service, and we’ll get a response. It’s running as a container.
I'll call my proxy service. You should see that the proxy service didn’t work because there was an incorrect API key.
localhost:8000/?key=test
I'll try it with the actual API key.
localhost:8000/?key=mysecretconsumerkey | json_pp
Now you should have reached the correct JSON form of data.
This plugin works like middleware and tries to find the correct key for each request.
## **What Custom Plugins Will You Build With Go?**
While JSON-based APIs are ubiquitous in the API-centric world of today, many industries adapted internet-based protocols for automated information exchange way before REST and JSON became popular. One attempt to establish a standardized protocol sui
Read the latest version: Kong Gateway Tutorial: Up and Running With a GUI in <15 Minutes Archived post below. You've decided to install Kong Gateway. Congrats! You're almost ready to accelerate your microservices journey with the world's most popul
Let's admit it - web services (SOAP) are here to stay for a few more years, and maybe for a long time in some places where there is no business incentive to rebuild them. However, with a decline in new SOAP web services and most applications moving
A common requirement for API gateways is to rewrite the published URL to a different URL for the upstream service’s endpoint. For example, due to legacy reasons, your upstream endpoint may have a base URI like /api/oilers/. However, you want your pub
Traditional APIs are, in a word, predictable. You know what you're getting: Compute costs that don't surprise you Traffic patterns that behave themselves Clean, well-defined request and response cycles AI APIs, especially anything that runs on LLMs
We're pleased to announce the launch of Standard Webhooks! Kong has been part of the Technical Committee of this standard with other great companies like Svix (the initiator of the project), Ngrok, Zapier, Twillio, Lob, Mux, and Supabase. This was
Today, we’re excited to release the Kong Konnect EKS Marketplace add-on as a means to deploy your Kong Gateway dataplanes in AWS. The add-ons are a step forward in providing fully managed Kubernetes clusters. It is here to simplify the post-procurem