rpc/connection/socket/servlet_handlers.go

44 lines
931 B
Go
Raw Normal View History

2017-11-26 10:15:51 +00:00
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
}