package socket import ( "net" "git.loafle.net/commons_go/rpc" "git.loafle.net/commons_go/rpc/protocol" ) type ServletHandlers struct { } func (sh *ServletHandlers) GetRequest(servletCTX rpc.ServletContext, codec protocol.ServerCodec, conn interface{}) (protocol.ServerRequestCodec, error) { nConn := conn.(net.Conn) requestCodec, err := codec.NewRequest(nConn) return requestCodec, err } func (sh *ServletHandlers) SendResponse(servletCTX rpc.ServletContext, conn interface{}, requestCodec protocol.ServerRequestCodec, result interface{}, err error) error { nConn := conn.(net.Conn) if nil != err { if wErr := requestCodec.WriteError(nConn, 500, err); nil != wErr { return wErr } } else { if wErr := requestCodec.WriteResponse(nConn, result); nil != wErr { return wErr } } return nil } func (sh *ServletHandlers) SendNotification(servletCTX rpc.ServletContext, conn interface{}, codec protocol.ServerCodec, method string, args ...interface{}) error { nConn := conn.(net.Conn) if wErr := codec.WriteNotification(nConn, method, args); nil != wErr { return wErr } return nil }