ing
This commit is contained in:
parent
6bcf814179
commit
1f366db739
52
server/rpc_server_handlers.go
Normal file
52
server/rpc_server_handlers.go
Normal file
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user