feat(*) add response phase (#32)

This commit is contained in:
Javier
2020-06-22 09:40:57 -05:00
committed by GitHub
parent c1ee697a37
commit 9cd14d59ec
2 changed files with 18 additions and 22 deletions

View File

@@ -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
View File

@@ -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)
}