From 1f366db73964c8d41b4f8b29715489b0bd2517f3 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 1 Nov 2017 19:05:50 +0900 Subject: [PATCH] ing --- server/rpc_server_handlers.go | 52 +++++++++++++++++++++++++++++++++++ server/server.go | 4 ++- server/server_handlers.go | 36 +----------------------- 3 files changed, 56 insertions(+), 36 deletions(-) create mode 100644 server/rpc_server_handlers.go diff --git a/server/rpc_server_handlers.go b/server/rpc_server_handlers.go new file mode 100644 index 0000000..55dac56 --- /dev/null +++ b/server/rpc_server_handlers.go @@ -0,0 +1,52 @@ +package server + +import ( + "io" + + "git.loafle.net/commons_go/rpc" + "git.loafle.net/commons_go/rpc/protocol/json" + "git.loafle.net/commons_go/rpc/server" +) + +func NewRPCServerHandler(registry rpc.Registry) *RPCServerHandlers { + rpcSH := &RPCServerHandlers{} + rpcSH.RPCRegistry = registry + + rpcSH.RegisterCodec(json.NewServerCodec(), "json") + + return rpcSH +} + +type RPCServerHandlers struct { + server.RPCServerHandlers + + addr string +} + +func (sh *ServerHandlers) GetContentType(r io.Reader) string { + return "json" +} + +func (sh *ServerHandlers) OnPreRead(r io.Reader) { + // no op +} + +func (sh *ServerHandlers) OnPostRead(r io.Reader) { + // no op +} + +func (sh *ServerHandlers) OnPreWriteResult(w io.Writer, result interface{}) { + // no op +} + +func (sh *ServerHandlers) OnPostWriteResult(w io.Writer, result interface{}) { + // no op +} + +func (sh *ServerHandlers) OnPreWriteError(w io.Writer, err error) { + // no op +} + +func (sh *ServerHandlers) OnPostWriteError(w io.Writer, err error) { + // no op +} diff --git a/server/server.go b/server/server.go index 09121b3..fd8faa9 100644 --- a/server/server.go +++ b/server/server.go @@ -7,7 +7,9 @@ import ( func New(addr string, registry rpc.Registry) server.Server { - sh := NewServerHandler(addr, registry) + sh := NewServerHandler(addr) + rpcSH := NewRPCServerHandler(registry) + sh.RPCServerHandler = rpcSH s := server.New(sh) diff --git a/server/server_handlers.go b/server/server_handlers.go index 963d71a..3b6f92b 100644 --- a/server/server_handlers.go +++ b/server/server_handlers.go @@ -1,22 +1,16 @@ package server import ( - "io" "net" "os" - "git.loafle.net/commons_go/rpc" - "git.loafle.net/commons_go/rpc/protocol/json" "git.loafle.net/commons_go/rpc/server" ) -func NewServerHandler(addr string, registry rpc.Registry) *ServerHandlers { +func NewServerHandler(addr string) *ServerHandlers { sh := &ServerHandlers{} - sh.RPCRegistry = registry sh.addr = addr - sh.RegisterCodec(json.NewServerCodec(), "json") - return sh } @@ -46,31 +40,3 @@ func (sh *ServerHandlers) Listen() (net.Listener, error) { func (sh *ServerHandlers) OnAccept(conn net.Conn) (net.Conn, error) { return conn, nil } - -func (sh *ServerHandlers) GetContentType(r io.Reader) string { - return "json" -} - -func (sh *ServerHandlers) OnPreRead(r io.Reader) { - // no op -} - -func (sh *ServerHandlers) OnPostRead(r io.Reader) { - // no op -} - -func (sh *ServerHandlers) OnPreWriteResult(w io.Writer, result interface{}) { - // no op -} - -func (sh *ServerHandlers) OnPostWriteResult(w io.Writer, result interface{}) { - // no op -} - -func (sh *ServerHandlers) OnPreWriteError(w io.Writer, err error) { - // no op -} - -func (sh *ServerHandlers) OnPostWriteError(w io.Writer, err error) { - // no op -}