golangci: enable bodyclose checker and fix related code

It has found an issue in the oracle code, so I think it's worth doing.
This commit is contained in:
Roman Khimov 2022-09-02 12:21:24 +03:00
parent df9a4fa7ce
commit 3c009271f8
7 changed files with 16 additions and 7 deletions

View file

@ -90,7 +90,10 @@ var errConnClosedByUser = errors.New("connection closed by user")
// operating on.
func NewWS(ctx context.Context, endpoint string, opts Options) (*WSClient, error) {
dialer := websocket.Dialer{HandshakeTimeout: opts.DialTimeout}
ws, _, err := dialer.Dial(endpoint, nil)
ws, resp, err := dialer.Dial(endpoint, nil)
if resp != nil && resp.Body != nil { // Can be non-nil even with error returned.
defer resp.Body.Close() // Not exactly required by websocket, but let's do this for bodyclose checker.
}
if err != nil {
return nil, err
}