add linter
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
install:
|
||||||
|
go get -t -v -u ./...
|
||||||
|
|
||||||
|
linter:
|
||||||
|
golangci-lint run --enable-all
|
||||||
|
|
||||||
|
test:
|
||||||
|
make linter
|
||||||
@@ -36,20 +36,20 @@ type RecConn struct {
|
|||||||
// Proxy specifies the proxy function for the dialer
|
// Proxy specifies the proxy function for the dialer
|
||||||
// defaults to ProxyFromEnvironment
|
// defaults to ProxyFromEnvironment
|
||||||
Proxy func(*http.Request) (*url.URL, error)
|
Proxy func(*http.Request) (*url.URL, error)
|
||||||
// NonVerbose suppress connecting/reconnecting messages.
|
|
||||||
NonVerbose bool
|
|
||||||
// SubscribeHandler fires after the connection successfully establish.
|
// SubscribeHandler fires after the connection successfully establish.
|
||||||
SubscribeHandler func() error
|
SubscribeHandler func() error
|
||||||
// KeepAliveTimeout is an interval for sending ping/pong messages
|
// KeepAliveTimeout is an interval for sending ping/pong messages
|
||||||
// disabled if 0
|
// disabled if 0
|
||||||
KeepAliveTimeout time.Duration
|
KeepAliveTimeout time.Duration
|
||||||
|
// NonVerbose suppress connecting/reconnecting messages.
|
||||||
|
NonVerbose bool
|
||||||
|
|
||||||
|
isConnected bool
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
url string
|
url string
|
||||||
reqHeader http.Header
|
reqHeader http.Header
|
||||||
httpResp *http.Response
|
httpResp *http.Response
|
||||||
dialErr error
|
dialErr error
|
||||||
isConnected bool
|
|
||||||
dialer *websocket.Dialer
|
dialer *websocket.Dialer
|
||||||
|
|
||||||
*websocket.Conn
|
*websocket.Conn
|
||||||
@@ -249,7 +249,7 @@ func (rc *RecConn) setDefaultDialer(handshakeTimeout time.Duration) {
|
|||||||
|
|
||||||
rc.dialer = &websocket.Dialer{
|
rc.dialer = &websocket.Dialer{
|
||||||
HandshakeTimeout: handshakeTimeout,
|
HandshakeTimeout: handshakeTimeout,
|
||||||
Proxy: rc.Proxy,
|
Proxy: rc.Proxy,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,13 +354,16 @@ func (rc *RecConn) keepAlive() {
|
|||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if (!rc.IsConnected()) {
|
if !rc.IsConnected() {
|
||||||
continue;
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rc.writeControlPingMessage(); err != nil {
|
||||||
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.writeControlPingMessage()
|
|
||||||
<-ticker.C
|
<-ticker.C
|
||||||
if time.Now().Sub(keepAliveResponse.getLastResponse()) > rc.getKeepAliveTimeout() {
|
if time.Since(keepAliveResponse.getLastResponse()) > rc.getKeepAliveTimeout() {
|
||||||
rc.closeAndReconnect()
|
rc.closeAndReconnect()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user