probe/client/central/cnetral.go

56 lines
1.3 KiB
Go
Raw Normal View History

2018-04-14 08:57:01 +00:00
package central
import (
"fmt"
"net/url"
"path"
crc "git.loafle.net/commons/rpc-go/client"
crpj "git.loafle.net/commons/rpc-go/protocol/json"
crr "git.loafle.net/commons/rpc-go/registry"
csc "git.loafle.net/commons/server-go/client"
csswc "git.loafle.net/commons/server-go/socket/web/client"
"git.loafle.net/overflow/probe/config"
)
func newConnector(name string, entryPath string) (*csswc.Connectors, error) {
2018-04-14 11:04:07 +00:00
config := config.GetConfig()
2018-04-14 08:57:01 +00:00
if nil == config {
return nil, fmt.Errorf("Config is not available")
}
u := url.URL{
Scheme: "ws",
Host: config.Central.Address,
}
u.Path = path.Join(u.Path, entryPath)
_connector := config.Central.Connector.Clone()
connector, ok := _connector.(*csswc.Connectors)
if !ok {
return nil, fmt.Errorf("Cannot convert to Connectors type")
}
connector.Name = name
connector.URL = u.String()
return connector, nil
}
func newClient(name string, connector csc.Connector, services []interface{}) *crc.Client {
codec := crpj.NewClientCodec()
var rpcRegistry crr.RPCRegistry
if nil != services && 0 < len(services) {
rpcRegistry = crr.NewRPCRegistry()
rpcRegistry.RegisterServices(services...)
}
return &crc.Client{
Connector: connector,
Codec: codec,
RPCInvoker: rpcRegistry,
Name: name,
}
}