diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d5018b5..e7c0ee9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,36 +15,35 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: 1.19.2 - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Lint - uses: golangci/golangci-lint-action@v2 - with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.53.3 - - # Optional: working directory, useful for monorepos - # working-directory: somedir - - # Optional: golangci-lint command line arguments. - # args: --issues-exit-code=0 - args: --config=.golangci.yml - - # Optional: show only new issues if it's a pull request. The default value is `false`. - only-new-issues: false - - - name: Get dependencies - run: | - go get -v -t -d ./... - - - name: Test - run: go test -v ./... - - - name: Build - run: go build -v . + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: 1.21.6 + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Lint + uses: golangci/golangci-lint-action@v2 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.55.2 + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # args: --issues-exit-code=0 + args: --config=.golangci.yml + + # Optional: show only new issues if it's a pull request. The default value is `false`. + only-new-issues: false + + - name: Get dependencies + run: | + go get -v -t -d ./... + - name: Test + run: go test -v ./... + + - name: Build + run: go build -v . diff --git a/.golangci.yml b/.golangci.yml index 75449c2..a67310c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,7 +2,6 @@ run: skip-dirs: - vendor/ skip-files: - - .gitignore - ".*_test.go$" output: @@ -47,6 +46,8 @@ linters-settings: gocyclo: # minimal code complexity to report, 30 by default (but we recommend 10-20) min-complexity: 15 + cyclop: + max-complexity: 15 godox: keywords: - "BUG" @@ -117,15 +118,75 @@ linters-settings: allow-trailing-comment: true # Force newlines in end of case at this limit (0 = never). force-case-trailing-whitespace: 0 + varnamelen: + # The longest distance, in source lines, that is being considered a "small scope." (defaults to 5) + # Variables used in at most this many lines will be ignored. + max-distance: 5 + # The minimum length of a variable's name that is considered "long." (defaults to 3) + # Variable names that are at least this long will be ignored. + min-name-length: 3 + # Check method receivers. (defaults to false) + check-receiver: false + # Check named return values. (defaults to false) + check-return: false + # Check type parameters. (defaults to false) + check-type-param: false + # Ignore "ok" variables that hold the bool return value of a type assertion. (defaults to false) + ignore-type-assert-ok: false + # Ignore "ok" variables that hold the bool return value of a map index. (defaults to false) + ignore-map-index-ok: false + # Ignore "ok" variables that hold the bool return value of a channel receive. (defaults to false) + ignore-chan-recv-ok: false + # Optional list of variable names that should be ignored completely. (defaults to empty list) + ignore-names: + - err + # Optional list of variable declarations that should be ignored completely. (defaults to empty list) + # Entries must be in one of the following forms (see below for examples): + # - for variables, parameters, named return values, method receivers, or type parameters: + # ( can also be a pointer/slice/map/chan/...) + # - for constants: const + ignore-decls: + - t testing.T + - f *foo.Bar + - e error + - i int + - n int + - const C + - T any + - m map[string]int + - x int + - y int + - w io.Writer + - r io.Reader + - i int64 + - f *os.File + - m int + - n int64 + - i int32 + - c *Context linters: enable-all: true disable: - - gomnd - - depguard + - interfacer # is deprecated (since v1.38.0) + - scopelint # is deprecated (since v1.39.0) + - golint # is deprecated (since v1.41.0) + - maligned # is deprecated (since v1.38.0) + - ifshort # is deprecated (since v1.48.0) + - deadcode # is deprecated (since v1.49.0) + - nosnakecase # is deprecated (since v1.48.1) + - varcheck # is deprecated (since v1.49.0) + - exhaustivestruct # is deprecated (since v1.46.0) + - structcheck # is deprecated (since v1.49.0) + - rowserrcheck # is disabled because of generics + - sqlclosecheck # is disabled because of generics + - structcheck # is disabled because of generics + - wastedassign # is disabled because of generics - tagliatelle - varnamelen - wrapcheck + - exhaustruct + - depguard issues: exclude: diff --git a/CHANGELOG.md b/CHANGELOG.md index ced1dc9..4e8db4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +## [v1.1.3] - 2024-02-03 +### Updated +- Updated Golang to 1.21.6 version. +- Updated golangci linter to 1.55.2 version. + ## [v1.1.2] - 2021-01-06 ### Updated - Updated golangci linter to 1.33 version in CI @@ -39,7 +44,8 @@ job was joined with tests workflow. ### Added - Initial implementation. -[Unreleased]: https://github.com/gorcon/websocket/compare/v1.1.2...HEAD +[Unreleased]: https://github.com/gorcon/websocket/compare/v1.1.3...HEAD +[v1.1.3]: https://github.com/gorcon/websocket/compare/v1.1.2...v1.1.3 [v1.1.2]: https://github.com/gorcon/websocket/compare/v1.1.1...v1.1.2 [v1.1.1]: 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 diff --git a/go.mod b/go.mod index 93347f8..ed1004d 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,7 @@ module github.com/gorcon/websocket -go 1.19 +go 1.21 -require github.com/gorilla/websocket v1.5.0 +require github.com/gorilla/websocket v1.5.1 + +require golang.org/x/net v0.17.0 // indirect diff --git a/go.sum b/go.sum index e5a03d4..272772f 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= diff --git a/message.go b/message.go index 779b234..4b0cc52 100644 --- a/message.go +++ b/message.go @@ -1,6 +1,11 @@ package websocket -import "math/rand" +import ( + "math/rand" + "time" +) + +const RandIdentifierLimit = 1000 // Message is both requests and responses are sent as packets wia WebSocket. // Their payload follows the following basic structure. @@ -28,6 +33,6 @@ type Message struct { func newMessage(command string) *Message { return &Message{ Message: command, - Identifier: rand.Intn(1000), + Identifier: rand.New(rand.NewSource(time.Now().UnixNano())).Intn(RandIdentifierLimit), } } diff --git a/websocket.go b/websocket.go index 17c6477..61c1a80 100644 --- a/websocket.go +++ b/websocket.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "fmt" - "math/rand" "net" "net/url" "time" @@ -62,8 +61,6 @@ func Dial(address string, password string, options ...Option) (*Conn, error) { return nil, fmt.Errorf("webrcon: %w", err) } - rand.Seed(time.Now().UnixNano()) - client := Conn{conn: conn, settings: settings} return &client, nil diff --git a/websocket_test.go b/websocket_test.go index d5a6a65..14e7155 100644 --- a/websocket_test.go +++ b/websocket_test.go @@ -167,7 +167,7 @@ func TestConn_Execute(t *testing.T) { conn.Close() result, err := conn.Execute("status") - wantErrMsg := fmt.Sprintf("webrcon: write tcp %s->%s: use of closed network connection", conn.LocalAddr(), conn.RemoteAddr()) + wantErrMsg := fmt.Sprintf("webrcon: set tcp %s: use of closed network connection", conn.LocalAddr()) if err == nil || err.Error() != wantErrMsg { t.Errorf("got err %q, want to contain %q", err, wantErrMsg) }