probe/client/connector.go

35 lines
697 B
Go
Raw Normal View History

2018-05-03 11:24:07 +00:00
package client
import (
"fmt"
"net/url"
"path"
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) {
config := config.GetConfig()
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
}