51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package client
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"path"
|
|
|
|
"git.loafle.net/commons/logging-go"
|
|
csc "git.loafle.net/commons/server-go/client"
|
|
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"
|
|
)
|
|
|
|
func NewConnector(containerType occp.ContainerType, portNumber int) (*csswc.Connectors, error) {
|
|
u := url.URL{
|
|
Scheme: "ws",
|
|
Host: fmt.Sprintf("127.0.0.1:%d", portNumber),
|
|
}
|
|
u.Path = path.Join(u.Path, occc.HTTPEntry_Container)
|
|
|
|
connector := &csswc.Connectors{
|
|
URL: u.String(),
|
|
}
|
|
|
|
connector.Name = containerType.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.RequestHeader = func() http.Header {
|
|
header := make(map[string][]string)
|
|
header[occc.HTTPRequestHeaderKey_Container_Method] = []string{occc.HTTPRequestHeaderValue_Container_Method_Connect}
|
|
header[occc.HTTPRequestHeaderKey_Container_Type] = []string{containerType.String()}
|
|
return header
|
|
}
|
|
connector.ResponseHandler = func(res *http.Response) {
|
|
}
|
|
connector.OnDisconnected = func(connector csc.Connector) {
|
|
logging.Logger().Debugf("Client[%s] has been disconnected", connector.GetName())
|
|
}
|
|
|
|
return connector, nil
|
|
}
|