rpc/connection/websocket/fasthttp/servlet_handlers.go
crusader fa7025303d ing
2017-11-27 00:49:56 +09:00

57 lines
1.3 KiB
Go

package fasthttp
import (
"fmt"
"git.loafle.net/commons_go/rpc/protocol"
"git.loafle.net/commons_go/websocket_fasthttp/websocket"
)
type ServletHandlers struct {
}
func (sh *ServletHandlers) GetRequest(codec protocol.ServerCodec, reader interface{}) (protocol.ServerRequestCodec, error) {
conn := reader.(*websocket.Conn)
_, r, err := conn.NextReader()
requestCodec, err := codec.NewRequest(r)
return requestCodec, err
}
func (sh *ServletHandlers) SendResponse(requestCodec protocol.ServerRequestCodec, writer interface{}, result interface{}, err error) error {
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")
}
func (sh *ServletHandlers) SendNotification(codec protocol.ServerCodec, writer interface{}, method string, args ...interface{}) error {
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")
}