Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions v2/delivery/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package delivery
import (
"net/http"
"net/url"
"sync/atomic"
"time"

"github.com/gorilla/websocket"
Expand Down Expand Up @@ -86,7 +87,7 @@ var wsServe = func(cfg *WsConfig, handler WsHandler, errHandler ErrHandler) (don
func keepAlive(c *websocket.Conn, timeout time.Duration) {
ticker := time.NewTicker(timeout)

lastResponse := time.Now()
var lastResponse int64 = time.Now().UnixNano()
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The explicit type declaration is unnecessary. Consider using short variable declaration: lastResponse := time.Now().UnixNano() for cleaner code.

Suggested change
var lastResponse int64 = time.Now().UnixNano()
lastResponse := time.Now().UnixNano()

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep lastResponse := ...?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


c.SetPingHandler(func(pingData string) error {
// Respond with Pong using the server's PING payload
Expand All @@ -99,7 +100,7 @@ func keepAlive(c *websocket.Conn, timeout time.Duration) {
return err
}

lastResponse = time.Now()
atomic.StoreInt64(&lastResponse, time.Now().UnixNano())

return nil
})
Expand All @@ -108,7 +109,8 @@ func keepAlive(c *websocket.Conn, timeout time.Duration) {
defer ticker.Stop()
for {
<-ticker.C
if time.Since(lastResponse) > timeout {
last := atomic.LoadInt64(&lastResponse)
if time.Since(time.Unix(0, last)) > timeout {
c.Close()
return
}
Expand Down
8 changes: 5 additions & 3 deletions v2/futures/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package futures
import (
"net/http"
"net/url"
"sync/atomic"
"time"

"github.com/gorilla/websocket"
Expand Down Expand Up @@ -86,7 +87,7 @@ var wsServe = func(cfg *WsConfig, handler WsHandler, errHandler ErrHandler) (don
func keepAlive(c *websocket.Conn, timeout time.Duration) {
ticker := time.NewTicker(timeout)

lastResponse := time.Now()
var lastResponse int64 = time.Now().UnixNano()
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The explicit type declaration is unnecessary. Consider using short variable declaration: lastResponse := time.Now().UnixNano() for cleaner code.

Suggested change
var lastResponse int64 = time.Now().UnixNano()
lastResponse := time.Now().UnixNano()

Copilot uses AI. Check for mistakes.

c.SetPingHandler(func(pingData string) error {
// Respond with Pong using the server's PING payload
Expand All @@ -99,7 +100,7 @@ func keepAlive(c *websocket.Conn, timeout time.Duration) {
return err
}

lastResponse = time.Now()
atomic.StoreInt64(&lastResponse, time.Now().UnixNano())

return nil
})
Expand All @@ -108,7 +109,8 @@ func keepAlive(c *websocket.Conn, timeout time.Duration) {
defer ticker.Stop()
for {
<-ticker.C
if time.Since(lastResponse) > timeout {
last := atomic.LoadInt64(&lastResponse)
if time.Since(time.Unix(0, last)) > timeout {
c.Close()
return
}
Expand Down
8 changes: 5 additions & 3 deletions v2/options/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package options
import (
"net/http"
"net/url"
"sync/atomic"
"time"

"github.com/gorilla/websocket"
Expand Down Expand Up @@ -87,7 +88,7 @@ var wsServe = func(cfg *WsConfig, handler WsHandler, errHandler ErrHandler) (don
func keepAlive(c *websocket.Conn, timeout time.Duration) {
ticker := time.NewTicker(timeout)

lastResponse := time.Now()
var lastResponse int64 = time.Now().UnixNano()
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The explicit type declaration is unnecessary. Consider using short variable declaration: lastResponse := time.Now().UnixNano() for cleaner code.

Suggested change
var lastResponse int64 = time.Now().UnixNano()
lastResponse := time.Now().UnixNano()

Copilot uses AI. Check for mistakes.

c.SetPingHandler(func(pingData string) error {
// Respond with Pong using the server's PING payload
Expand All @@ -100,7 +101,7 @@ func keepAlive(c *websocket.Conn, timeout time.Duration) {
return err
}

lastResponse = time.Now()
atomic.StoreInt64(&lastResponse, time.Now().UnixNano())

return nil
})
Expand All @@ -109,7 +110,8 @@ func keepAlive(c *websocket.Conn, timeout time.Duration) {
defer ticker.Stop()
for {
<-ticker.C
if time.Since(lastResponse) > timeout {
last := atomic.LoadInt64(&lastResponse)
if time.Since(time.Unix(0, last)) > timeout {
c.Close()
return
}
Expand Down
8 changes: 5 additions & 3 deletions v2/portfolio/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package portfolio
import (
"net/http"
"net/url"
"sync/atomic"
"time"

"github.com/gorilla/websocket"
Expand Down Expand Up @@ -86,7 +87,7 @@ var wsServe = func(cfg *WsConfig, handler WsHandler, errHandler ErrHandler) (don
func keepAlive(c *websocket.Conn, timeout time.Duration) {
ticker := time.NewTicker(timeout)

lastResponse := time.Now()
var lastResponse int64 = time.Now().UnixNano()
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The explicit type declaration is unnecessary. Consider using short variable declaration: lastResponse := time.Now().UnixNano() for cleaner code.

Suggested change
var lastResponse int64 = time.Now().UnixNano()
lastResponse := time.Now().UnixNano()

Copilot uses AI. Check for mistakes.

c.SetPingHandler(func(pingData string) error {
// Respond with Pong using the server's PING payload
Expand All @@ -99,7 +100,7 @@ func keepAlive(c *websocket.Conn, timeout time.Duration) {
return err
}

lastResponse = time.Now()
atomic.StoreInt64(&lastResponse, time.Now().UnixNano())

return nil
})
Expand All @@ -108,7 +109,8 @@ func keepAlive(c *websocket.Conn, timeout time.Duration) {
defer ticker.Stop()
for {
<-ticker.C
if time.Since(lastResponse) > timeout {
last := atomic.LoadInt64(&lastResponse)
if time.Since(time.Unix(0, last)) > timeout {
c.Close()
return
}
Expand Down
8 changes: 5 additions & 3 deletions v2/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package binance
import (
"net/http"
"net/url"
"sync/atomic"
"time"

"github.com/gorilla/websocket"
Expand Down Expand Up @@ -90,7 +91,7 @@ var wsServe = func(cfg *WsConfig, handler WsHandler, errHandler ErrHandler) (don
func keepAlive(c *websocket.Conn, timeout time.Duration) {
ticker := time.NewTicker(timeout)

lastResponse := time.Now()
var lastResponse int64 = time.Now().UnixNano()
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The explicit type declaration is unnecessary. Consider using short variable declaration: lastResponse := time.Now().UnixNano() for cleaner code.

Suggested change
var lastResponse int64 = time.Now().UnixNano()
lastResponse := time.Now().UnixNano()

Copilot uses AI. Check for mistakes.

c.SetPingHandler(func(pingData string) error {
// Respond with Pong using the server's PING payload
Expand All @@ -103,7 +104,7 @@ func keepAlive(c *websocket.Conn, timeout time.Duration) {
return err
}

lastResponse = time.Now()
atomic.StoreInt64(&lastResponse, time.Now().UnixNano())

return nil
})
Expand All @@ -112,7 +113,8 @@ func keepAlive(c *websocket.Conn, timeout time.Duration) {
defer ticker.Stop()
for {
<-ticker.C
if time.Since(lastResponse) > timeout {
last := atomic.LoadInt64(&lastResponse)
if time.Since(time.Unix(0, last)) > timeout {
c.Close()
return
}
Expand Down