github.com/Kong/go-pdk@v0.11.0/server/event.go (about) 1 package server 2 3 import ( 4 "fmt" 5 ) 6 7 // Incoming data for a new event. 8 // TODO: add some relevant data to reduce number of callbacks. 9 type StartEventData struct { 10 InstanceId int // Instance ID to start the event 11 EventName string // event name (not handler method name) 12 // .... 13 } 14 15 type eventData struct { 16 ipc chan interface{} // communication channel (TODO: use decoded structs) 17 } 18 19 // A callback's response/request. 20 type StepData struct { 21 EventId int // event cycle to which this belongs 22 Data interface{} // carried data 23 } 24 25 // Step carries a callback's answer back from Kong to the plugin, 26 // the return value is either a new callback request or a finish signal. 27 // 28 // RPC exported method 29 func (rh *rpcHandler) Step(in StepData, out *StepData) error { 30 rh.lock.RLock() 31 event, ok := rh.events[in.EventId] 32 rh.lock.RUnlock() 33 if !ok { 34 return fmt.Errorf("no running event %d", in.EventId) 35 } 36 37 event.ipc <- in.Data 38 outStr := <-event.ipc 39 *out = StepData{EventId: in.EventId, Data: outStr} 40 41 return nil 42 }