rpc/connection/websocket/fasthttp/servlet_handlers.go

58 lines
1.4 KiB
Go
Raw Normal View History

2017-11-26 10:15:51 +00:00
package fasthttp
import (
"fmt"
2017-11-27 16:22:02 +00:00
"git.loafle.net/commons_go/rpc"
2017-11-26 10:15:51 +00:00
"git.loafle.net/commons_go/rpc/protocol"
"git.loafle.net/commons_go/websocket_fasthttp/websocket"
)
type ServletHandlers struct {
}
2017-11-27 16:22:02 +00:00
func (sh *ServletHandlers) GetRequest(servletCTX rpc.ServletContext, codec protocol.ServerCodec, reader interface{}) (protocol.ServerRequestCodec, error) {
2017-11-26 10:15:51 +00:00
conn := reader.(*websocket.Conn)
_, r, err := conn.NextReader()
requestCodec, err := codec.NewRequest(r)
return requestCodec, err
}
2017-11-27 16:22:02 +00:00
func (sh *ServletHandlers) SendResponse(servletCTX rpc.ServletContext, requestCodec protocol.ServerRequestCodec, writer interface{}, result interface{}, err error) error {
2017-11-26 10:15:51 +00:00
conn := writer.(*websocket.Conn)
wc, lerr := conn.NextWriter(websocket.TextMessage)
if nil != lerr {
}
if nil != err {
if lerr := requestCodec.WriteError(wc, 500, err); nil != lerr {
}
} else {
if err := requestCodec.WriteResponse(wc, result); nil != err {
}
}
return fmt.Errorf("Servlet Handler: SendResponse is not implemented")
}
2017-11-27 16:22:02 +00:00
func (sh *ServletHandlers) SendNotification(servletCTX rpc.ServletContext, codec protocol.ServerCodec, writer interface{}, method string, args ...interface{}) error {
2017-11-26 10:15:51 +00:00
conn := writer.(*websocket.Conn)
wc, lerr := conn.NextWriter(websocket.TextMessage)
if nil != lerr {
}
if err := codec.WriteNotification(wc, method, args); nil != err {
}
return fmt.Errorf("Servlet Handler: SendNotification is not implemented")
}