mirror of
https://github.com/Kong/go-pluginserver.git
synced 2025-10-05 16:17:01 +08:00
refactor(*) split for readability
Split event and instance handling code into their own modules.
This commit is contained in:

committed by
Guilherme Salazar

parent
1af48ef618
commit
9c17f1c76f
43
main.go
Normal file
43
main.go
Normal file
@@ -0,0 +1,43 @@
|
||||
// go-pluginserver is a standalone RPC server that runs
|
||||
// Go plugins for Kong.
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/ugorji/go/codec"
|
||||
"log"
|
||||
"net"
|
||||
"net/rpc"
|
||||
)
|
||||
|
||||
var socket = flag.String("socket", "", "Socket to listen into")
|
||||
|
||||
func runServer(listener net.Listener) {
|
||||
var handle codec.MsgpackHandle
|
||||
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
log.Printf("accept(): %s", err)
|
||||
return
|
||||
}
|
||||
rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, &handle)
|
||||
rpc.ServeCodec(rpcCodec)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
if *socket != "" {
|
||||
listener, err := net.Listen("unix", *socket)
|
||||
if err != nil {
|
||||
log.Printf(`listen("%s"): %s`, socket, err)
|
||||
return
|
||||
}
|
||||
|
||||
rpc.RegisterName("plugin", newServer())
|
||||
|
||||
runServer(listener)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user