46 lines
995 B
Go
46 lines
995 B
Go
package socket
|
|
|
|
import (
|
|
"io"
|
|
|
|
"git.loafle.net/commons_go/rpc/protocol"
|
|
"git.loafle.net/commons_go/rpc/server"
|
|
)
|
|
|
|
type ServletHandlers struct {
|
|
server.ServletHandlers
|
|
}
|
|
|
|
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
|
|
}
|