Giter Site home page Giter Site logo

go-plugins's Introduction

⚠️ This repository is no longer maintained. Examples are now in the go-pdk repo

Kong Go Plugins

Example code of Kong plugins written in Go. These are not plugins intended for production use, but rather small examples to get you started writing your own:

  • go-hello: a "hello world" plugin, which reads a request header and sets a response header.
  • go-hello-lm: same as the previous as a loadble module to use with the go-pluginserver.
  • go-log: a reimplementation of Kong's file-log plugin in Go. shows the use of go I/O, goroutines and long-lived globals.
  • go-log-lm: same as go-log but built as a loadable module to use with the go-pluginserver.

go-plugins's People

Contributors

fffonion avatar gszr avatar hishamhm avatar javierguerragiraldez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-plugins's Issues

Kong is getting stop again and again

kong | 2022/08/19 13:43:56 [notice] 30#0: signal 17 (SIGCHLD) received from 91
kong | 2022/08/19 13:43:56 [notice] 30#0: *14 [kong] go.lua:95 go-pluginserver terminated: exit 2, context: ngx.timer
kong | 2022/08/19 13:43:56 [notice] 30#0: *14 [kong] go.lua:84 Starting go-pluginserver, context: ngx.timer

I'm facing this issue, kong is getting stop and stop again and again , how can I resolve this issue??

Consider moving plugins to separate folders to make valid go module

At the moment all plugin examples are situated at the root of the repo which is bad practice as the code is not a valid go module. There are multiple main files and other conflicting declarations meaning that the you cannot generically build the repo or write test files.

For instance write a test file and see the following errors:

 go build .
# github.com/Kong/go-plugins
.\go-hello.go:20:5: Version redeclared in this block
        .\go-hello-lm.go:15:5: other declaration of Version
.\go-hello.go:21:5: Priority redeclared in this block
        .\go-hello-lm.go:16:5: other declaration of Priority
.\go-hello.go:23:6: Config redeclared in this block
        .\go-hello-lm.go:18:6: other declaration of Config
.\go-hello.go:27:6: New redeclared in this block
        .\go-hello-lm.go:22:6: other declaration of New
.\go-log-lm.go:11:6: Config redeclared in this block
        .\go-hello-lm.go:18:6: other declaration of Config
.\go-log-lm.go:19:6: New redeclared in this block
        .\go-hello-lm.go:22:6: other declaration of New
.\go-log.go:29:6: main redeclared in this block
        .\go-hello.go:16:6: other declaration of main
.\go-log.go:35:6: Config redeclared in this block
        .\go-hello-lm.go:18:6: other declaration of Config
.\go-log.go:48:5: fileDescriptors redeclared in this block
        .\go-log-lm.go:16:5: other declaration of fileDescriptors
.\go-log.go:49:5: channels redeclared in this block
        .\go-log-lm.go:17:5: other declaration of channels
.\go-log.go:49:5: too many errors

It would be good it these examples followed go best practices to separate main files into separate folders.

How to install this plugin?

The code is very simple and clear for understanding, but I have question about how to install this plugin.

My kong version is 2.2.1.

Testing Go Plugins

How does one go about writing unit/integration tests for go plugins? Examples are in this repo but no test examples.

I know lua plugins have kong-pongo, is there a go variant?

go-pluginserver error die loop

error.log:
2020/04/09 20:42:49 [notice] 32346#0: signal 17 (SIGCHLD) received from 19941
2020/04/09 20:42:49 [notice] 32346#0: *13 [kong] go.lua:95 go-pluginserver terminated: exit 0, context: ngx.timer
centos 7

go-pluginserver -version
Version: development
Runtime Version: go1.13.5

go-pluginserver -dump-plugin-info go-hello -plugins-directory $(pwd)
2020/04/09 20:47:47 failed to open plugin go-hello: plugin.Open("/root/go-plugins/go-hello"): plugin was built with a different version of package internal/cpu

How to use these plugins?

How to use these plugins? Any example or the guide will be of great help.
I followed below steps:

  1. added go_plugins_dir = /usr/local/kong/goplugins inside the kong.conf file
  2. created the folder at /usr/local/kong/goplugins and added go-hello.go from https://github.com/Kong/go-plugins
  3. Tried finding the same through curl localhost:8001 but can not find go-hello

output of above curl
{"plugins":{"enabled_in_cluster":["jwt-custom","prometheus","rate-limiting","syslog","file-log"],"available_on_server":{"correlation-id":true,"pre-function":true,"cors":true,"ldap-auth":true,"loggly":true,"hmac-auth":true,"zipkin":true,"request-size-limiting":true,"azure-functions":true,"request-transformer":true,"oauth2":true,"response-transformer":true,"ip-restriction":true,"statsd":true,"jwt":true,"proxy-cache":true,"basic-auth":true,"key-auth":true,"http-log":true,"ab-user":true,"jwt-custom":true,"datadog":true,"tcp-log":true,"rate-limiting":true,"post-function":true,"prometheus":true,"acl":true,"syslog":true,"file-log":true,"acme":true,"udp-log":true,"response-ratelimiting":true,"aws-lambda":true,"session":true,"bot-detection":true,"request-termination":true}},"tagline":"Welcome to kong","configuration":{"plugins":["bundled","jwt-custom","ab-user"],"admin_listen":["0.0.0.0:8001","0.0.0.0:8444 ssl"],"lua_ssl_verify_depth":1,"prefix":"\/usr\/local\/kong","nginx_conf":"\/usr\/local\/kong\/nginx.conf","cassandra_username":"kong","nginx_events_directives":[{"value":"auto","name":"worker_connections"},{"value":"on","name":"multi_accept"}],"admin_ssl_cert_key":"\/usr\/local\/kong\/ssl\/admin-kong-default.key","dns_resolver":{},"nginx_upstream_keepalive_requests":"100","nginx_http_upstream_directives":[{"value":"100","name":"keepalive_requests"},{"value":"60s","name":"keepalive_timeout"},{"value":"60","name":"keepalive"}],"nginx_main_daemon":"on","stream_proxy_ssl_enabled":false,"nginx_acc_logs":"\/usr\/local\/kong\/logs\/access.log","pg_semaphore_timeout":60000,"proxy_listen":["0.0.0.0:8000 reuseport backlog=16384","0.0.0.0:8443 http2 ssl reuseport backlog=16384"],"client_ssl_cert_default":"\/usr\/local\/kong\/ssl\/kong-default.crt","go_pluginserver_exe":"\/usr\/local\/bin\/go-pluginserver","dns_no_sync":false,"db_update_propagation":0,"stream_listen":["off"],"nginx_err_logs":"\/usr\/local\/kong\/logs\/error.log","cassandra_port":9042,"headers":["server_tokens","latency_tokens"],"nginx_http_client_max_body_size":"0","status_listen":["off"],"cassandra_lb_policy":"RequestRoundRobin","cluster_control_plane":"127.0.0.1:8005","nginx_http_ssl_prefer_server_ciphers":"off","pg_database":"kong","lua_package_cpath":"","admin_acc_logs":"\/usr\/local\/kong\/logs\/admin_access.log","cassandra_refresh_frequency":60,"nginx_pid":"\/usr\/local\/kong\/pids\/nginx.pid","nginx_main_worker_rlimit_nofile":"auto","admin_access_log":"logs\/admin_access.log","proxy_listeners":[{"listener":"0.0.0.0:8000 reuseport backlog=16384","proxy_protocol":false,"reuseport":true,"deferred":false,"ssl":false,"ip":"0.0.0.0","backlog=16384":true,"http2":false,"port":8000,"bind":false},{"listener":"0.0.0.0:8443 ssl http2 reuseport backlog=16384","proxy_protocol":false,"reuseport":true,"deferred":false,"ssl":true,"ip":"0.0.0.0","backlog=16384":true,"http2":true,"port":8443,"bind":false}],"db_cache_warmup_entities":["services","plugins"],"enabled_headers":{"latency_tokens":true,"X-Kong-Response-Latency":true,"Server":true,"X-Kong-Admin-Latency":true,"X-Kong-Upstream-Status":false,"Via":true,"X-Kong-Proxy-Latency":true,"server_tokens":true,"X-Kong-Upstream-Latency":true},"nginx_http_ssl_protocols":"TLSv1.2 TLSv1.3","db_cache_ttl":0,"nginx_events_multi_accept":"on","admin_ssl_cert_default":"\/usr\/local\/kong\/ssl\/admin-kong-default.crt","pg_ssl":false,"status_access_log":"off","cluster_listeners":[{"listener":"0.0.0.0:8005","proxy_protocol":false,"reuseport":false,"backlog=%d+":false,"deferred":false,"ssl":false,"ip":"0.0.0.0","port":8005,"http2":false,"bind":false}],"kong_env":"\/usr\/local\/kong\/.kong_env","cassandra_schema_consensus_timeout":60000,"log_level":"notice","admin_ssl_cert_key_default":"\/usr\/local\/kong\/ssl\/admin-kong-default.key","real_ip_recursive":"off","cassandra_repl_factor":1,"nginx_main_worker_processes":"auto","router_consistency":"strict","pg_port":5432,"cassandra_keyspace":"kong","ssl_cert_default":"\/usr\/local\/kong\/ssl\/kong-default.crt","nginx_http_ssl_session_timeout":"1d","error_default_type":"text\/plain","role":"traditional","client_ssl":false,"trusted_ips":{},"nginx_events_worker_connections":"auto","nginx_supstream_directives":{},"ssl_cert_key":"\/usr\/local\/kong\/ssl\/kong-default.key","pg_user":"kong","pg_password":"******","ssl_ciphers":"ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384","nginx_admin_directives":{},"nginx_upstream_keepalive_timeout":"60s","nginx_http_directives":[{"value":"0","name":"client_max_body_size"},{"value":"off","name":"ssl_prefer_server_ciphers"},{"value":"8k","name":"client_body_buffer_size"},{"value":"TLSv1.2 TLSv1.3","name":"ssl_protocols"},{"value":"on","name":"ssl_session_tickets"},{"value":"1d","name":"ssl_session_timeout"},{"value":"prometheus_metrics 5m","name":"lua_shared_dict"}],"pg_host":"hawkeye-qa.cavqxjfmp25f.ap-south-1.rds.amazonaws.com","nginx_kong_stream_conf":"\/usr\/local\/kong\/nginx-kong-stream.conf","ssl_cert_key_default":"\/usr\/local\/kong\/ssl\/kong-default.key","go_plugins_dir":"\/usr\/local\/kong\/goplugins","db_update_frequency":5,"dns_order":["LAST","SRV","A","CNAME"],"dns_error_ttl":1,"nginx_optimizations":true,"nginx_http_upstream_keepalive_timeout":"60s","pg_timeout":60000,"nginx_http_upstream_keepalive_requests":"100","database":"postgres","nginx_upstream_keepalive":"60","nginx_worker_processes":"auto","nginx_http_status_directives":{},"lua_package_path":".\/?.lua;.\/?\/init.lua;","router_update_frequency":1,"upstream_keepalive":60,"pg_max_concurrent_queries":0,"proxy_ssl_enabled":true,"nginx_http_upstream_keepalive":"60","lua_socket_pool_size":30,"mem_cache_size":"128m","loaded_plugins":{"correlation-id":true,"pre-function":true,"cors":true,"ldap-auth":true,"loggly":true,"hmac-auth":true,"zipkin":true,"request-size-limiting":true,"azure-functions":true,"request-transformer":true,"oauth2":true,"response-transformer":true,"syslog":true,"statsd":true,"acme":true,"proxy-cache":true,"basic-auth":true,"key-auth":true,"http-log":true,"jwt":true,"bot-detection":true,"ab-user":true,"tcp-log":true,"session":true,"post-function":true,"datadog":true,"acl":true,"ip-restriction":true,"file-log":true,"jwt-custom":true,"udp-log":true,"response-ratelimiting":true,"aws-lambda":true,"rate-limiting":true,"prometheus":true,"request-termination":true},"db_resurrect_ttl":30,"cassandra_data_centers":["dc1:2","dc2:3"],"cassandra_consistency":"ONE","client_max_body_size":"0","admin_error_log":"logs\/error.log","pg_ssl_verify":false,"dns_not_found_ttl":30,"nginx_http_ssl_session_tickets":"on","dns_stale_ttl":4,"ssl_cipher_suite":"intermediate","cassandra_repl_strategy":"SimpleStrategy","status_error_log":"logs\/status_error.log","nginx_http_client_body_buffer_size":"8k","kic":false,"cluster_listen":["0.0.0.0:8005"],"nginx_kong_conf":"\/usr\/local\/kong\/nginx-kong.conf","real_ip_header":"X-Real-IP","dns_hostsfile":"\/etc\/hosts","admin_listeners":[{"listener":"0.0.0.0:8001","proxy_protocol":false,"reuseport":false,"backlog=%d+":false,"deferred":false,"ssl":false,"ip":"0.0.0.0","port":8001,"http2":false,"bind":false},{"listener":"0.0.0.0:8444 ssl","proxy_protocol":false,"reuseport":false,"backlog=%d+":false,"deferred":false,"ssl":true,"ip":"0.0.0.0","port":8444,"http2":false,"bind":false}],"ssl_cert_csr_default":"\/usr\/local\/kong\/ssl\/kong-default.csr","ssl_cert":"\/usr\/local\/kong\/ssl\/kong-default.crt","nginx_proxy_real_ip_recursive":"off","nginx_status_directives":{},"cassandra_ssl_verify":false,"cassandra_ssl":false,"admin_ssl_cert":"\/usr\/local\/kong\/ssl\/admin-kong-default.crt","proxy_error_log":"logs\/error.log","nginx_sproxy_directives":{},"nginx_proxy_directives":[{"value":"X-Real-IP","name":"real_ip_header"},{"value":"off","name":"real_ip_recursive"}],"nginx_daemon":"on","anonymous_reports":true,"cassandra_timeout":60000,"nginx_main_directives":[{"value":"on","name":"daemon"},{"value":"auto","name":"worker_rlimit_nofile"},{"value":"auto","name":"worker_processes"}],"status_listeners":{},"client_ssl_cert_key_default":"\/usr\/local\/kong\/ssl\/kong-default.key","client_body_buffer_size":"8k","cassandra_contact_points":["127.0.0.1"],"nginx_upstream_directives":[{"value":"100","name":"keepalive_requests"},{"value":"60s","name":"keepalive_timeout"},{"value":"60","name":"keepalive"}],"admin_ssl_enabled":true,"stream_listeners":{},"nginx_proxy_real_ip_header":"X-Real-IP","proxy_access_log":"logs\/access.log","nginx_stream_directives":[{"value":"stream_prometheus_metrics 5m","name":"lua_shared_dict"}]},"version":"2.0.4","node_id":"e6e5fc6d-c4ae-41aa-8218-639c5faad58e","lua_version":"LuaJIT 2.1.0-beta3","prng_seeds":{"pid: 3271":792341169209,"pid: 3270":199173721770,"pid: 3261":219124362351},"timers":{"pending":9,"running":2},"hostname":"ip-x.y.z"}

Testing Go Plugins

How does one go about writing unit/integration tests for go plugins? Examples are in this repo but no test examples.

I know lua plugins have kong-pongo, is there a go variant?

how can i set request header?

example in go-hello only set header in response

but i want to set header berfor kong pass request to backend svc

i dig into to the kong.Request,but i only find Getxxx

please help me out

package management?

Just running make doesn't work, as it need the github.com/Kong/go-pdk module - irrespective of the path of the repository.

May be we can have a package management system? I would recommend using golang modules, but that's available only after go 1.11 . Is that's okay, I would be willing to raise a PR with go.mod and go.sum 😄

With go modules, people can place the repository anywhere and still make it work

go-pluginserver terminated: exit 0, context: ngx.timer

I ran go-hello plugin on ubuntu18.04 os,but encounter problems below:

2020/04/01 11:30:33 [notice] 18798#0: *9 [kong] go.lua:95 go-pluginserver terminated: exit 0, context: ngx.timer 2020/04/01 11:30:33 [notice] 18798#0: *9 [kong] go.lua:84 Starting go-pluginserver, context: ngx.timer

with the error log file keep refreshing until stop kong.
Many thanks!

Initialization code

As in Lua we have init_worker to initialize libraries needed in Access, I cannot seem to find the right place to add the initialization code for some encryption libraries ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.