This commit is contained in:
crusader 2017-11-30 14:34:15 +09:00
parent 824265e5a7
commit 4c113374e9

View File

@ -3,17 +3,28 @@ package fasthttp
import (
"github.com/gorilla/websocket"
"git.loafle.net/commons_go/logging"
"git.loafle.net/commons_go/rpc/client"
"git.loafle.net/commons_go/rpc/protocol"
cwf "git.loafle.net/commons_go/websocket_fasthttp"
cwfc "git.loafle.net/commons_go/websocket_fasthttp/client"
)
func New() client.ClientReadWriteCloseHandler {
return &ClientReadWriteCloseHandlers{}
func New(socketBuilder cwfc.SocketBuilder) client.ClientReadWriteCloseHandler {
return &ClientReadWriteCloseHandlers{
SocketBuilder: socketBuilder,
}
}
type ClientReadWriteCloseHandlers struct {
client.ClientReadWriteCloseHandlers
SocketBuilder cwfc.SocketBuilder
}
func (crwch *ClientReadWriteCloseHandlers) Connect(clientCTX client.ClientContext) (interface{}, error) {
return cwfc.NewSocket(crwch.SocketBuilder, clientCTX)
}
func (crwch *ClientReadWriteCloseHandlers) ReadResponse(clientCTX client.ClientContext, codec protocol.ClientCodec, conn interface{}) (protocol.ClientResponseCodec, error) {
@ -50,4 +61,9 @@ func (crwch *ClientReadWriteCloseHandlers) Disconnect(clientCTX client.ClientCon
func (crwch *ClientReadWriteCloseHandlers) Validate() {
crwch.ClientReadWriteCloseHandlers.Validate()
if nil == crwch.SocketBuilder {
logging.Logger().Panic("RPC Client: SocketBuilder must be specified")
}
}