mirror of
https://github.com/Kong/go-pluginserver.git
synced 2025-09-27 04:26:20 +08:00
feat(*) add response phase (#32)
This commit is contained in:
28
instance.go
28
instance.go
@@ -20,30 +20,27 @@ type instanceData struct {
|
||||
}
|
||||
|
||||
type (
|
||||
certificater interface{ Certificate(*pdk.PDK) }
|
||||
rewriter interface{ Rewrite(*pdk.PDK) }
|
||||
accesser interface{ Access(*pdk.PDK) }
|
||||
headerFilter interface{ HeaderFilter(*pdk.PDK) }
|
||||
bodyFilter interface{ BodyFilter(*pdk.PDK) }
|
||||
prereader interface{ Preread(*pdk.PDK) }
|
||||
logger interface{ Log(*pdk.PDK) }
|
||||
certificater interface{ Certificate(*pdk.PDK) }
|
||||
rewriter interface{ Rewrite(*pdk.PDK) }
|
||||
accesser interface{ Access(*pdk.PDK) }
|
||||
responser interface{ Response(*pdk.PDK) }
|
||||
prereader interface{ Preread(*pdk.PDK) }
|
||||
logger interface{ Log(*pdk.PDK) }
|
||||
)
|
||||
|
||||
func getHandlers(config interface{}) map[string]func(kong *pdk.PDK) {
|
||||
handlers := map[string]func(kong *pdk.PDK){}
|
||||
|
||||
if h, ok := config.(certificater); ok { handlers["certificate"] = h.Certificate }
|
||||
if h, ok := config.(rewriter) ; ok { handlers["rewrite"] = h.Rewrite }
|
||||
if h, ok := config.(accesser) ; ok { handlers["access"] = h.Access }
|
||||
if h, ok := config.(headerFilter); ok { handlers["header_filter"] = h.HeaderFilter }
|
||||
if h, ok := config.(bodyFilter) ; ok { handlers["body_filter"] = h.BodyFilter }
|
||||
if h, ok := config.(prereader) ; ok { handlers["preread"] = h.Preread }
|
||||
if h, ok := config.(logger) ; ok { handlers["log"] = h.Log }
|
||||
if h, ok := config.(certificater); ok { handlers["certificate"] = h.Certificate }
|
||||
if h, ok := config.(rewriter) ; ok { handlers["rewrite"] = h.Rewrite }
|
||||
if h, ok := config.(accesser) ; ok { handlers["access"] = h.Access }
|
||||
if h, ok := config.(responser) ; ok { handlers["response"] = h.Response }
|
||||
if h, ok := config.(prereader) ; ok { handlers["preread"] = h.Preread }
|
||||
if h, ok := config.(logger) ; ok { handlers["log"] = h.Log }
|
||||
|
||||
return handlers
|
||||
}
|
||||
|
||||
|
||||
func (s *PluginServer) expireInstances() error {
|
||||
const instanceTimeout = 60
|
||||
expirationCutoff := time.Now().Add(time.Second * -instanceTimeout)
|
||||
@@ -131,7 +128,6 @@ func (s *PluginServer) StartInstance(config PluginConfig, status *InstanceStatus
|
||||
|
||||
log.Printf("Started instance %#v:%v", config.Name, instance.id)
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
12
main.go
12
main.go
@@ -4,14 +4,14 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"runtime"
|
||||
"fmt"
|
||||
"github.com/ugorji/go/codec"
|
||||
"log"
|
||||
"net"
|
||||
"net/rpc"
|
||||
"os"
|
||||
"reflect"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -19,9 +19,9 @@ var version = "development"
|
||||
|
||||
/* flags */
|
||||
var (
|
||||
kongPrefix = flag.String("kong-prefix", "/usr/local/kong", "Kong prefix path (specified by the -p argument commonly used in the kong cli)")
|
||||
dump = flag.String("dump-plugin-info", "", "Dump info about `plugin` as a MessagePack object")
|
||||
pluginsDir = flag.String("plugins-directory", "", "Set directory `path` where to search plugins")
|
||||
kongPrefix = flag.String("kong-prefix", "/usr/local/kong", "Kong prefix path (specified by the -p argument commonly used in the kong cli)")
|
||||
dump = flag.String("dump-plugin-info", "", "Dump info about `plugin` as a MessagePack object")
|
||||
pluginsDir = flag.String("plugins-directory", "", "Set directory `path` where to search plugins")
|
||||
showVersion = flag.Bool("version", false, "Print binary and runtime version")
|
||||
)
|
||||
|
||||
@@ -118,7 +118,7 @@ func main() {
|
||||
if socket != "" {
|
||||
go func() {
|
||||
for {
|
||||
if ! isParentAlive() {
|
||||
if !isParentAlive() {
|
||||
log.Printf("Kong exited; shutting down...")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
Reference in New Issue
Block a user