probe/client/client.go
crusader d5cb6e03c8 ing
2018-07-02 17:08:37 +09:00

30 lines
795 B
Go

package client
import (
crc "git.loafle.net/commons/rpc-go/client"
crcodec "git.loafle.net/commons/rpc-go/codec"
crpj "git.loafle.net/commons/rpc-go/protocol/json"
crr "git.loafle.net/commons/rpc-go/registry"
cssc "git.loafle.net/commons/server-go/socket/client"
)
func New(name string, connector cssc.Connector, services []interface{}) *crc.Client {
codec := crpj.NewCustomClientCodec(crcodec.NewCompressionCodecSelector(connector.GetCompressionThreshold()))
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,
}
}