Skip to content

Commit

Permalink
Up golangci linter to 1.33 version
Browse files Browse the repository at this point in the history
  • Loading branch information
outdead committed Jan 5, 2021
1 parent f8fbfd2 commit 2666b94
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,5 @@ issues:
exclude:
- "G404: Use of weak random number generator \\(math/rand instead of crypto/rand\\)" # gosec
- "shadow: declaration of \"err\"" # govet
- "`DefaultSettings` is a global variable" # gochecknoglobals
- "DefaultSettings`? is a global variable" # gochecknoglobals
- "are|is missing in" # exhaustivestruct # v1.33
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [v1.1.1] - 2021-01-06
### Updated
- Updated golangci linter to 1.33 version

### Changed
- Changed errors handling - added wrapping.

## [v1.1.0] - 2020-12-14
### Changed
- Replaced testify/assert to native tests.
Expand All @@ -28,7 +35,8 @@ job was joined with tests workflow.
### Added
- Initial implementation.

[Unreleased]: https://github.com/gorcon/websocket/compare/v1.1.0...HEAD
[Unreleased]: https://github.com/gorcon/websocket/compare/v1.0.1...HEAD
[v1.1.0]: https://github.com/gorcon/websocket/compare/v1.1.0...v1.1.1
[v1.1.0]: https://github.com/gorcon/websocket/compare/v1.0.1...v1.1.0
[v1.0.1]: https://github.com/gorcon/websocket/compare/v1.0.0...v1.0.1
[v1.0.0]: https://github.com/gorcon/websocket/compare/v0.1.0...v1.0.0
22 changes: 15 additions & 7 deletions websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package websocket
import (
"encoding/json"
"errors"
"fmt"
"math/rand"
"net"
"net/url"
Expand Down Expand Up @@ -58,7 +59,7 @@ func Dial(address string, password string, options ...Option) (*Conn, error) {
return nil, ErrAuthFailed
}

return nil, err
return nil, fmt.Errorf("webrcon: %w", err)
}

rand.Seed(time.Now().UnixNano())
Expand All @@ -82,7 +83,7 @@ func (c *Conn) Execute(command string) (string, error) {

data, err := json.Marshal(request)
if err != nil {
return "", err
return "", fmt.Errorf("webrcon: %w", err)
}

if err := c.write(data); err != nil {
Expand All @@ -97,7 +98,7 @@ func (c *Conn) Execute(command string) (string, error) {

var response Message
if err := json.Unmarshal(p, &response); err != nil {
return "", err
return "", fmt.Errorf("webrcon: %w", err)
}

if response.Identifier == request.Identifier {
Expand All @@ -124,21 +125,28 @@ func (c *Conn) Close() error {
func (c *Conn) write(data []byte) error {
if c.settings.deadline != 0 {
if err := c.conn.SetWriteDeadline(time.Now().Add(c.settings.deadline)); err != nil {
return err
return fmt.Errorf("webrcon: %w", err)
}
}

return c.conn.WriteMessage(websocket.TextMessage, data)
if err := c.conn.WriteMessage(websocket.TextMessage, data); err != nil {
return fmt.Errorf("webrcon: %w", err)
}

return nil
}

func (c *Conn) read() ([]byte, error) {
if c.settings.deadline != 0 {
if err := c.conn.SetReadDeadline(time.Now().Add(c.settings.deadline)); err != nil {
return nil, err
return nil, fmt.Errorf("webrcon: %w", err)
}
}

_, p, err := c.conn.ReadMessage()
if err != nil {
return p, fmt.Errorf("webrcon: %w", err)
}

return p, err
return p, nil
}
4 changes: 2 additions & 2 deletions websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestConn_Execute(t *testing.T) {
conn.Close()

result, err := conn.Execute("status")
wantErrMsg := fmt.Sprintf("write tcp %s->%s: use of closed network connection", conn.LocalAddr(), conn.RemoteAddr())
wantErrMsg := fmt.Sprintf("webrcon: write tcp %s->%s: use of closed network connection", conn.LocalAddr(), conn.RemoteAddr())
if err == nil || err.Error() != wantErrMsg {
t.Errorf("got err %q, want to contain %q", err, wantErrMsg)
}
Expand All @@ -185,7 +185,7 @@ func TestConn_Execute(t *testing.T) {
defer conn.Close()

result, err := conn.Execute("deadline")
wantErrMsg := fmt.Sprintf("read tcp %s->%s: i/o timeout", conn.LocalAddr(), conn.RemoteAddr())
wantErrMsg := fmt.Sprintf("webrcon: read tcp %s->%s: i/o timeout", conn.LocalAddr(), conn.RemoteAddr())
if err == nil || err.Error() != wantErrMsg {
t.Errorf("got err %q, want to contain %q", err, wantErrMsg)
}
Expand Down

0 comments on commit 2666b94

Please sign in to comment.