rpc/client/rwc/websocket/fasthttp/client_rwc_handlers.go
crusader 824265e5a7 ing
2017-11-30 13:59:46 +09:00

54 lines
1.3 KiB
Go

package fasthttp
import (
"github.com/gorilla/websocket"
"git.loafle.net/commons_go/rpc/client"
"git.loafle.net/commons_go/rpc/protocol"
cwf "git.loafle.net/commons_go/websocket_fasthttp"
)
func New() client.ClientReadWriteCloseHandler {
return &ClientReadWriteCloseHandlers{}
}
type ClientReadWriteCloseHandlers struct {
client.ClientReadWriteCloseHandlers
}
func (crwch *ClientReadWriteCloseHandlers) ReadResponse(clientCTX client.ClientContext, codec protocol.ClientCodec, conn interface{}) (protocol.ClientResponseCodec, error) {
soc := conn.(cwf.Socket)
_, r, err := soc.NextReader()
resCodec, err := codec.NewResponse(r)
return resCodec, err
}
func (crwch *ClientReadWriteCloseHandlers) WriteRequest(clientCTX client.ClientContext, codec protocol.ClientCodec, conn interface{}, method string, params interface{}, id interface{}) error {
soc := conn.(cwf.Socket)
wc, wErr := soc.NextWriter(websocket.TextMessage)
if nil != wErr {
return wErr
}
defer func() {
wc.Close()
}()
if wErr := codec.WriteRequest(wc, method, params, id); nil != wErr {
return wErr
}
return nil
}
func (crwch *ClientReadWriteCloseHandlers) Disconnect(clientCTX client.ClientContext, conn interface{}) {
soc := conn.(cwf.Socket)
soc.Close()
}
func (crwch *ClientReadWriteCloseHandlers) Validate() {
crwch.ClientReadWriteCloseHandlers.Validate()
}