package socket import ( "io" "git.loafle.net/commons_go/rpc/protocol" ) type ServletHandlers struct { } func (sh *ServletHandlers) GetRequest(codec protocol.ServerCodec, reader interface{}) (protocol.ServerRequestCodec, error) { r := reader.(io.Reader) requestCodec, err := codec.NewRequest(r) return requestCodec, err } func (sh *ServletHandlers) SendResponse(requestCodec protocol.ServerRequestCodec, writer interface{}, result interface{}, err error) error { w := writer.(io.Writer) if nil != err { if lerr := requestCodec.WriteError(w, 500, err); nil != lerr { } } else { if err := requestCodec.WriteResponse(w, result); nil != err { } } return nil } func (sh *ServletHandlers) SendNotification(codec protocol.ServerCodec, writer interface{}, method string, args ...interface{}) error { w := writer.(io.Writer) if err := codec.WriteNotification(w, method, args); nil != err { } return nil }