container-go/client/client.go

41 lines
1014 B
Go
Raw Normal View History

2018-05-02 10:59:45 +00:00
package client
import (
"fmt"
"net/url"
"path"
"git.loafle.net/commons/logging-go"
csswc "git.loafle.net/commons/server-go/socket/web/client"
occc "git.loafle.net/overflow/commons-go/config/container"
occp "git.loafle.net/overflow/commons-go/config/probe"
)
2018-05-03 06:14:22 +00:00
func NewConnector(containerType occp.ContainerType, portNumber int) (*csswc.Connectors, error) {
2018-05-02 10:59:45 +00:00
u := url.URL{
Scheme: "ws",
2018-05-03 06:15:43 +00:00
Host: fmt.Sprintf("127.0.0.1:%d", portNumber),
2018-05-02 10:59:45 +00:00
}
u.Path = path.Join(u.Path, occc.HTTPEntry_Container)
connector := &csswc.Connectors{
Name: containerType.String(),
URL: u.String(),
}
connector.ReconnectInterval = 5
connector.ReconnectTryTime = 2
connector.MaxMessageSize = 4096
connector.ReadBufferSize = 4096
connector.WriteBufferSize = 4096
connector.PongTimeout = 60
connector.PingTimeout = 10
connector.PingPeriod = 9
connector.OnDisconnected = func(connector csc.Connector) {
logging.Logger().Debugf("Client[%s] has been disconnected", connector.GetName())
}
return connector, nil
}