package socket import ( "net" "git.loafle.net/commons_go/rpc" "git.loafle.net/commons_go/rpc/protocol" ) type ServletHandlers struct { } func (sh *ServletHandlers) ReadRequest(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) WriteResponse(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) WriteNotification(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 }