2018-05-03 11:24:07 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
crc "git.loafle.net/commons/rpc-go/client"
|
2018-07-02 08:08:37 +00:00
|
|
|
crcodec "git.loafle.net/commons/rpc-go/codec"
|
2018-05-03 11:24:07 +00:00
|
|
|
crpj "git.loafle.net/commons/rpc-go/protocol/json"
|
|
|
|
crr "git.loafle.net/commons/rpc-go/registry"
|
2018-07-01 04:09:50 +00:00
|
|
|
cssc "git.loafle.net/commons/server-go/socket/client"
|
2018-05-03 11:24:07 +00:00
|
|
|
)
|
|
|
|
|
2018-07-01 04:09:50 +00:00
|
|
|
func New(name string, connector cssc.Connector, services []interface{}) *crc.Client {
|
2018-07-02 08:08:37 +00:00
|
|
|
codec := crpj.NewCustomClientCodec(crcodec.NewCompressionCodecSelector(connector.GetCompressionThreshold()))
|
2018-05-03 11:24:07 +00:00
|
|
|
|
|
|
|
var rpcRegistry crr.RPCRegistry
|
|
|
|
if nil != services && 0 < len(services) {
|
|
|
|
rpcRegistry = crr.NewRPCRegistry()
|
|
|
|
rpcRegistry.RegisterServices(services...)
|
|
|
|
}
|
|
|
|
|
|
|
|
ch := &ClientHandlers{}
|
|
|
|
ch.Name = name
|
|
|
|
ch.Connector = connector
|
|
|
|
ch.RPCCodec = codec
|
|
|
|
ch.RPCInvoker = rpcRegistry
|
|
|
|
|
|
|
|
return &crc.Client{
|
|
|
|
ClientHandler: ch,
|
|
|
|
}
|
|
|
|
}
|