container-go/client/client.go
crusader 519e96beea ing
2018-07-04 11:35:52 +09:00

52 lines
1.5 KiB
Go

package client
import (
"fmt"
"net/http"
"net/url"
"path"
"git.loafle.net/commons/logging-go"
cssc "git.loafle.net/commons/server-go/socket/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 = 8192
connector.ReadBufferSize = 8192
connector.WriteBufferSize = 8192
connector.PongTimeout = 60
connector.PingTimeout = 10
connector.PingPeriod = 9
connector.CompressionThreshold = 4096
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 cssc.Connector) {
logging.Logger().Debugf("Client[%s] has been disconnected", connector.GetName())
}
return connector, nil
}