This commit is contained in:
crusader 2017-12-05 14:40:31 +09:00
parent c3cd65f72d
commit 6614bd5489
4 changed files with 8 additions and 14 deletions

View File

@ -1,13 +1,15 @@
package server package server
import ( import (
crpj "git.loafle.net/commons_go/rpc/protocol/json"
crr "git.loafle.net/commons_go/rpc/registry" crr "git.loafle.net/commons_go/rpc/registry"
"git.loafle.net/commons_go/rpc/server" "git.loafle.net/commons_go/rpc/server"
) )
func newRPCServletHandler(rpcInvoker crr.RPCInvoker) server.ServletHandler { func NewRPCServletHandler(rpcInvoker crr.RPCInvoker) server.ServletHandler {
sh := &RPCServletHandlers{} sh := &RPCServletHandlers{}
sh.RPCInvoker = rpcInvoker sh.RPCInvoker = rpcInvoker
sh.RegisterCodec(crpj.Name, crpj.NewServerCodec())
return sh return sh
} }

View File

@ -1,19 +1,11 @@
package server package server
import ( import (
crpj "git.loafle.net/commons_go/rpc/protocol/json"
crr "git.loafle.net/commons_go/rpc/registry"
"git.loafle.net/commons_go/server" "git.loafle.net/commons_go/server"
) )
func New(addr string, serverName string, rpcInvoker crr.RPCInvoker) server.Server { func New(serverHandler ServerHandler) server.Server {
rpcSH := newRPCServletHandler(rpcInvoker) s := server.New(serverHandler)
rpcSH.RegisterCodec(crpj.Name, crpj.NewServerCodec())
socketHandler := newSocketHandler(rpcSH)
sh := newServerHandler(addr, serverName, socketHandler)
s := server.New(sh)
return s return s
} }

View File

@ -7,7 +7,7 @@ import (
"git.loafle.net/commons_go/server" "git.loafle.net/commons_go/server"
) )
func newServerHandler(addr string, serverName string, socketHandler SocketHandler) ServerHandler { func NewServerHandler(addr string, serverName string, socketHandler SocketHandler) ServerHandler {
sh := &ServerHandlers{ sh := &ServerHandlers{
addr: addr, addr: addr,
} }

View File

@ -12,7 +12,7 @@ import (
oopc "git.loafle.net/overflow/overflow_probe_container" oopc "git.loafle.net/overflow/overflow_probe_container"
) )
func newSocketHandler(rpcSH RPCServletHandler) SocketHandler { func NewSocketHandler(rpcSH RPCServletHandler) SocketHandler {
rpcRWCSH := crsrs.New() rpcRWCSH := crsrs.New()
sh := &SocketHandlers{ sh := &SocketHandlers{
@ -39,7 +39,7 @@ func (sh *SocketHandlers) Init(serverCTX server.ServerContext) error {
} }
func (sh *SocketHandlers) Handshake(socketCTX server.SocketContext, conn net.Conn) (id string) { func (sh *SocketHandlers) Handshake(socketCTX server.SocketContext, conn net.Conn) (id string) {
return "discovery" return "server"
} }
func (sh *SocketHandlers) OnConnect(soc server.Socket) { func (sh *SocketHandlers) OnConnect(soc server.Socket) {