github.com/Kong/go-pdk@v0.11.0/pdk.go (about) 1 /* 2 Package Kong/go-pdk implements Kong's Plugin Development Kit for Go. 3 4 It directly parallels the existing kong PDK for Lua plugins. 5 6 Kong plugins written in Go implement event handlers as methods on the Plugin's 7 structure, with the given signature: 8 9 func (conf *MyConfig) Access (kong *pdk.PDK) { 10 ... 11 } 12 13 The `kong` argument of type `*pdk.PDK` is the entrypoint for all PDK functions. 14 For example, to get the client's IP address, you'd use `kong.Client.GetIp()`. 15 */ 16 package pdk 17 18 import ( 19 "net" 20 21 "github.com/Kong/go-pdk/bridge" 22 "github.com/Kong/go-pdk/client" 23 "github.com/Kong/go-pdk/ctx" 24 "github.com/Kong/go-pdk/ip" 25 "github.com/Kong/go-pdk/log" 26 "github.com/Kong/go-pdk/nginx" 27 "github.com/Kong/go-pdk/node" 28 "github.com/Kong/go-pdk/request" 29 "github.com/Kong/go-pdk/response" 30 "github.com/Kong/go-pdk/router" 31 "github.com/Kong/go-pdk/service" 32 service_request "github.com/Kong/go-pdk/service/request" 33 service_response "github.com/Kong/go-pdk/service/response" 34 ) 35 36 // PDK go pdk module 37 type PDK struct { 38 Client client.Client 39 Ctx ctx.Ctx 40 Log log.Log 41 Nginx nginx.Nginx 42 Request request.Request 43 Response response.Response 44 Router router.Router 45 IP ip.Ip 46 Node node.Node 47 Service service.Service 48 ServiceRequest service_request.Request 49 ServiceResponse service_response.Response 50 } 51 52 // Init initialize go pdk. Called by the pluginserver at initialization. 53 func Init(conn net.Conn) *PDK { 54 b := bridge.New(conn) 55 return &PDK{ 56 Client: client.Client{b}, 57 Ctx: ctx.Ctx{b}, 58 Log: log.Log{b}, 59 Nginx: nginx.Nginx{b}, 60 Request: request.Request{b}, 61 Response: response.Response{b}, 62 Router: router.Router{b}, 63 IP: ip.Ip{b}, 64 Node: node.Node{b}, 65 Service: service.Service{b}, 66 ServiceRequest: service_request.Request{b}, 67 ServiceResponse: service_response.Response{b}, 68 } 69 }