diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..7c50107 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,37 @@ +name: Lint +on: + pull_request: + types: + - opened + - edited + - synchronize +jobs: + lint-commit-message: + name: Metadata + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Commit Message + run: .github/lint-commit-message.sh + + - name: File names + run: .github/lint-filename.sh + + - name: Contributors + run: .github/assert-contributors.sh + + - name: Functions + run: .github/lint-disallowed-functions-in-library.sh + + lint-go: + name: Go + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: golangci-lint + uses: golangci/golangci-lint-action@v1 + with: + version: v1.31 + args: $GOLANGCI_LINT_EXRA_ARGS diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..aec55b9 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,132 @@ +name: Test +on: + push: + branches: + - master + pull_request: + branches: + - master +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + go: ["1.14", "1.15"] + name: Go ${{ matrix.go }} + steps: + - uses: actions/checkout@v2 + + - name: Setup Go + uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go }} + + - name: Set test packages + run: echo ::set-env name=TEST_PACKAGES::$(go list ./... | grep -v examples) + + - name: Run test + run: | + go test \ + -coverprofile=cover.out -covermode=atomic \ + ${TEST_EXTRA_ARGS:-} \ + -v -race ${TEST_PACKAGES} + + - uses: codecov/codecov-action@v1 + with: + file: ./cover.out + name: codecov-umbrella + fail_ci_if_error: true + flags: go + + test-i386: + runs-on: ubuntu-latest + strategy: + matrix: + go: ["1.14", "1.15"] + name: Go i386 ${{ matrix.go }} + steps: + - uses: actions/checkout@v2 + + - uses: actions/cache@v2 + with: + path: | + ~/go/pkg/mod + ~/.cache + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Set test packages + run: echo ::set-env name=TEST_PACKAGES::$(go list ./... | grep -v examples) + + - name: Run test + run: | + docker run \ + -u $(id -u):$(id -g) \ + -e "GO111MODULE=on" \ + -e "CGO_ENABLED=0" \ + -v $GITHUB_WORKSPACE:/go/src/github.com/pion/$(basename $GITHUB_WORKSPACE) \ + -v $HOME/go/pkg/mod:/go/pkg/mod \ + -v $HOME/.cache:/.cache \ + -w /go/src/github.com/pion/$(basename $GITHUB_WORKSPACE) \ + i386/golang:${{matrix.go}}-alpine \ + /usr/local/go/bin/go test \ + ${TEST_EXTRA_ARGS:-} \ + -v ${TEST_PACKAGES} + + test-wasm: + runs-on: ubuntu-latest + name: WASM + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: '12.x' + + - uses: actions/cache@v2 + with: + path: | + ~/go/pkg/mod + ~/.cache + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Set test packages + run: echo ::set-env name=TEST_PACKAGES::$(go list ./... | grep -v examples) + + - name: Download Go + run: curl -sSfL https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz | tar -C ~ -xzf - + env: + GO_VERSION: 1.15 + + - name: Set Go Root + run: echo ::set-env name=GOROOT::${HOME}/go + + - name: Set Go Path + run: echo ::set-env name=GOPATH::${HOME}/go + + - name: Update Path + run: echo ::set-env name=PATH::${GOROOT}/bin:${PATH} + + - name: Set Go WASM Exec + run: echo ::set-env name=GO_JS_WASM_EXEC::${GOROOT}/misc/wasm/go_js_wasm_exec + + - name: Insall NPM modules + run: yarn install + + - name: Run Tests + run: | + GOOS=js GOARCH=wasm go test \ + -coverprofile=cover.out -covermode=atomic \ + -exec="${GO_JS_WASM_EXEC}" \ + -v ${TEST_PACKAGES} + + - uses: codecov/codecov-action@v1 + with: + file: ./cover.out + name: codecov-umbrella + fail_ci_if_error: true + flags: wasm diff --git a/.golangci.yml b/.golangci.yml index 40ca69c..570f17b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,93 +1,8 @@ linters-settings: govet: check-shadowing: true - golint: - min-confidence: 0 - gocyclo: - min-complexity: 15 - maligned: - suggest-new: true - dupl: - threshold: 100 - goconst: - min-len: 2 - min-occurrences: 2 misspell: locale: US - lll: - line-length: 140 - goimports: - local-prefixes: github.com/pion - gocritic: - enabled-tags: - - performance - - style - - experimental - disabled-checks: - - commentedOutCode - - sloppyReassign - -issues: - exclude: - - "`assertHMACSize` - `blocksize` always receives `64`" - exclude-rules: - - text: "string ``" - linters: - - goconst - - # Exclude some linters from running on tests files. - - path: _test\.go - linters: - - gocyclo - - errcheck - - dupl - - gosec - - goconst - - # Ease some gocritic warnings on test files. - - path: _test\.go - text: "(unnamedResult|exitAfterDefer|unlambda)" - linters: - - gocritic - - # Exclude known linters from partially hard-vendored code, - # which is impossible to exclude via "nolint" comments. - - path: internal/hmac/ - text: "weak cryptographic primitive" - linters: - - gosec - - path: internal/hmac/ - text: "Write\\` is not checked" - linters: - - errcheck - - # Ease linting on benchmarking code. - - path: cmd/stun-bench/ - linters: - - gosec - - errcheck - - unparam - - - path: ^cmd/ - linters: - - gocyclo - - path: ^cmd/ - text: "(unnamedResult|exitAfterDefer)" - linters: - - gocritic - -linters: - enable-all: true - disable: - - funlen - - gochecknoglobals - - godox - - prealloc - - scopelint run: - skip-dirs: - - e2e - - fuzz - - testdata - - api + skip-dirs-use-default: false diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 43eb708..0000000 --- a/.travis.yml +++ /dev/null @@ -1,142 +0,0 @@ -# -# DO NOT EDIT THIS FILE -# -# It is automatically copied from https://github.com/pion/.goassets repository. -# If this repository should have package specific CI config, -# remove the repository name from .goassets/.github/workflows/assets-sync.yml. -# -# If you want to update the shared CI config, send a PR to -# https://github.com/pion/.goassets instead of this repository. -# - -dist: bionic -language: go - - -branches: - only: - - master - -env: - global: - - GO111MODULE=on - - GOLANGCI_LINT_VERSION=1.19.1 - -cache: - directories: - - ${HOME}/.cache/go-build - - ${GOPATH}/pkg/mod - npm: true - yarn: true - -_lint_job: &lint_job - env: CACHE_NAME=lint - before_install: - - if [ -f .github/.ci.conf ]; then . .github/.ci.conf; fi - install: skip - before_script: - - | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \ - | bash -s - -b $GOPATH/bin v${GOLANGCI_LINT_VERSION} - script: - - bash .github/assert-contributors.sh - - bash .github/lint-disallowed-functions-in-library.sh - - bash .github/lint-commit-message.sh - - bash .github/lint-filename.sh - - golangci-lint run ${GOLANGCI_LINT_EXRA_ARGS:-} ./... -_test_job: &test_job - env: CACHE_NAME=test - before_install: - - if [ -f .github/.ci.conf ]; then . .github/.ci.conf; fi - - go mod download - install: - - go build ./... - script: - # If you want to specify repository specific test packages rule, - # add `TEST_PACKAGES=$(command to list test target packages)` to .github/.ci.conf - - testpkgs=${TEST_PACKAGES:-$(go list ./... | grep -v examples)} - - coverpkgs=$(echo "${testpkgs}" | paste -s -d ',') - - | - go test \ - -coverpkg=${coverpkgs} -coverprofile=cover.out -covermode=atomic \ - ${TEST_EXTRA_ARGS:-} \ - -v -race ${testpkgs} - - if [ -n "${TEST_HOOK}" ]; then ${TEST_HOOK}; fi - after_success: - - travis_retry bash <(curl -s https://codecov.io/bash) -c -F go -_test_i386_job: &test_i386_job - env: CACHE_NAME=test386 - services: docker - before_install: - - if [ -f .github/.ci.conf ]; then . .github/.ci.conf; fi - script: - - testpkgs=${TEST_PACKAGES:-$(go list ./... | grep -v examples)} - - | - docker run \ - -u $(id -u):$(id -g) \ - -e "GO111MODULE=on" \ - -e "CGO_ENABLED=0" \ - -v ${PWD}:/go/src/github.com/pion/$(basename ${PWD}) \ - -v ${HOME}/gopath/pkg/mod:/go/pkg/mod \ - -v ${HOME}/.cache/go-build:/.cache/go-build \ - -w /go/src/github.com/pion/$(basename ${PWD}) \ - -it i386/golang:${GO_VERSION}-alpine \ - /usr/local/go/bin/go test \ - ${TEST_EXTRA_ARGS:-} \ - -v ${testpkgs} -_test_wasm_job: &test_wasm_job - env: CACHE_NAME=wasm - language: node_js - node_js: 12 - before_install: - - if [ -f .github/.ci.conf ]; then . .github/.ci.conf; fi - - if ${SKIP_WASM_TEST:-false}; then exit 0; fi - install: - # Manually download and install Go instead of using gimme. - # It looks like gimme Go causes some errors on go-test for Wasm. - - curl -sSfL https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz | tar -C ~ -xzf - - - export GOROOT=${HOME}/go - - export PATH=${GOROOT}/bin:${PATH} - - yarn install - - export GO_JS_WASM_EXEC=${GO_JS_WASM_EXEC:-${GOROOT}/misc/wasm/go_js_wasm_exec} - script: - - testpkgs=${TEST_PACKAGES:-$(go list ./... | grep -v examples)} - - coverpkgs=$(echo "${testpkgs}" | paste -s -d ',') - - | - GOOS=js GOARCH=wasm go test \ - -coverpkg=${coverpkgs} -coverprofile=cover.out -covermode=atomic \ - -exec="${GO_JS_WASM_EXEC}" \ - -v ${testpkgs} - after_success: - - travis_retry bash <(curl -s https://codecov.io/bash) -c -F wasm - -jobs: - include: - - <<: *lint_job - name: Lint 1.15 - go: 1.15 - - <<: *test_job - name: Test 1.14 - go: 1.14 - - <<: *test_job - name: Test 1.15 - go: 1.15 - - <<: *test_i386_job - name: Test i386 1.14 - env: GO_VERSION=1.14 - go: 1.15 # Go version for host environment only for `go list`. - # All tests are done on the version specified by GO_VERSION. - - <<: *test_i386_job - name: Test i386 1.15 - env: GO_VERSION=1.15 - go: 1.15 # Go version for host environment only for `go list`. - # All tests are done on the version specified by GO_VERSION. - - <<: *test_wasm_job - name: Test WASM 1.14 - env: GO_VERSION=1.14 - - <<: *test_wasm_job - name: Test WASM 1.15 - env: GO_VERSION=1.15 - -notifications: - email: false diff --git a/agent_test.go b/agent_test.go index 245429a..373988a 100644 --- a/agent_test.go +++ b/agent_test.go @@ -129,7 +129,7 @@ func TestAgent_GC(t *testing.T) { ) gcDeadline := deadline.Add(-time.Second) deadlineNotGC := gcDeadline.AddDate(0, 0, -1) - a.SetHandler(func(e Event) { + a.SetHandler(func(e Event) { //nolint: errcheck id := e.TransactionID shouldTimeOut, found := shouldTimeOutID[id] if !found { diff --git a/attributes_test.go b/attributes_test.go index 6df873a..a8a7a7b 100644 --- a/attributes_test.go +++ b/attributes_test.go @@ -9,7 +9,7 @@ func BenchmarkMessage_GetNotFound(b *testing.B) { m := New() b.ReportAllocs() for i := 0; i < b.N; i++ { - m.Get(AttrRealm) + m.Get(AttrRealm) //nolint: errcheck } } @@ -18,7 +18,7 @@ func BenchmarkMessage_Get(b *testing.B) { m.Add(AttrUsername, []byte{1, 2, 3, 4, 5, 6, 7}) b.ReportAllocs() for i := 0; i < b.N; i++ { - m.Get(AttrUsername) + m.Get(AttrUsername) //nolint: errcheck } } @@ -42,12 +42,12 @@ func TestRawAttribute_AddTo(t *testing.T) { func TestMessage_GetNoAllocs(t *testing.T) { m := New() - NewSoftware("c").AddTo(m) + NewSoftware("c").AddTo(m) //nolint: errcheck m.WriteHeader() t.Run("Default", func(t *testing.T) { allocs := testing.AllocsPerRun(10, func() { - m.Get(AttrSoftware) + m.Get(AttrSoftware) //nolint: errcheck }) if allocs > 0 { t.Error("allocated memory, but should not") @@ -55,7 +55,7 @@ func TestMessage_GetNoAllocs(t *testing.T) { }) t.Run("Not found", func(t *testing.T) { allocs := testing.AllocsPerRun(10, func() { - m.Get(AttrOrigin) + m.Get(AttrOrigin) //nolint: errcheck }) if allocs > 0 { t.Error("allocated memory, but should not") diff --git a/client_test.go b/client_test.go index 0934be7..dbd35c8 100644 --- a/client_test.go +++ b/client_test.go @@ -83,7 +83,7 @@ func BenchmarkClient_Do(b *testing.B) { } }() m := New() - m.NewTransactionID() + m.NewTransactionID() //nolint: errcheck m.Encode() for pb.Next() { if err := client.Do(m, noopF); err != nil { @@ -1426,7 +1426,7 @@ func TestClientImmediateTimeout(t *testing.T) { } gotReads <- struct{}{} }() - c.Start(MustBuild(response, BindingRequest), func(e Event) { + c.Start(MustBuild(response, BindingRequest), func(e Event) { //nolint: errcheck if e.Error == ErrTransactionTimeOut { t.Error("unexpected error") } diff --git a/cmd/stun-bench/main.go b/cmd/stun-bench/main.go index e0f6027..2bd5837 100644 --- a/cmd/stun-bench/main.go +++ b/cmd/stun-bench/main.go @@ -20,7 +20,7 @@ import ( var ( workers = flag.Int("w", runtime.GOMAXPROCS(0), "concurrent workers") - addr = flag.String("addr", fmt.Sprintf("localhost"), "target address") + addr = flag.String("addr", "localhost", "target address") port = flag.Int("port", stun.DefaultPort, "target port") duration = flag.Duration("d", time.Minute, "benchmark duration") network = flag.String("net", "udp", "protocol to use (udp, tcp)") @@ -95,7 +95,9 @@ func main() { req := stun.New() for { if *realRand { - rand.Read(req.TransactionID[:]) + if _, err := rand.Read(req.TransactionID[:]); err != nil { + log.Fatal("rand.Read failed:", err) + } } else { mathRand.Read(req.TransactionID[:]) } diff --git a/cmd/stun-traversal/main.go b/cmd/stun-traversal/main.go index b51dce7..a84009b 100644 --- a/cmd/stun-traversal/main.go +++ b/cmd/stun-traversal/main.go @@ -14,7 +14,7 @@ import ( ) var ( - server = flag.String("server", fmt.Sprintf("pion.ly:3478"), "Stun server address") + server = flag.String("server", "pion.ly:3478", "Stun server address") ) const ( diff --git a/errorcode_test.go b/errorcode_test.go index f2d8a53..77a8d46 100644 --- a/errorcode_test.go +++ b/errorcode_test.go @@ -12,7 +12,7 @@ func BenchmarkErrorCode_AddTo(b *testing.B) { m := New() b.ReportAllocs() for i := 0; i < b.N; i++ { - CodeStaleNonce.AddTo(m) + CodeStaleNonce.AddTo(m) //nolint: errcheck m.Reset() } } @@ -25,7 +25,7 @@ func BenchmarkErrorCodeAttribute_AddTo(b *testing.B) { Reason: []byte("not found!"), } for i := 0; i < b.N; i++ { - a.AddTo(m) + a.AddTo(m) //nolint: errcheck m.Reset() } } @@ -37,9 +37,9 @@ func BenchmarkErrorCodeAttribute_GetFrom(b *testing.B) { Code: 404, Reason: []byte("not found!"), } - a.AddTo(m) + a.AddTo(m) //nolint: errcheck for i := 0; i < b.N; i++ { - a.GetFrom(m) + a.GetFrom(m) //nolint: errcheck } } @@ -63,7 +63,7 @@ func TestMessage_AddErrorCode(t *testing.T) { copy(m.TransactionID[:], transactionID) expectedCode := ErrorCode(438) expectedReason := "Stale Nonce" - CodeStaleNonce.AddTo(m) + CodeStaleNonce.AddTo(m) //nolint: errcheck m.WriteHeader() mRes := New() diff --git a/fingerprint_test.go b/fingerprint_test.go index 1cb42f4..0f595bd 100644 --- a/fingerprint_test.go +++ b/fingerprint_test.go @@ -18,7 +18,7 @@ func BenchmarkFingerprint_AddTo(b *testing.B) { addAttr(b, m, s) b.SetBytes(int64(len(m.Raw))) for i := 0; i < b.N; i++ { - Fingerprint.AddTo(m) + Fingerprint.AddTo(m) //nolint: errcheck m.WriteLength() m.Length -= attributeHeaderSize + fingerprintSize m.Raw = m.Raw[:m.Length+messageHeaderSize] @@ -30,7 +30,7 @@ func TestFingerprint_Check(t *testing.T) { m := new(Message) addAttr(t, m, NewSoftware("software")) m.WriteHeader() - Fingerprint.AddTo(m) + Fingerprint.AddTo(m) //nolint: errcheck m.WriteHeader() if err := Fingerprint.Check(m); err != nil { t.Error(err) @@ -64,7 +64,7 @@ func BenchmarkFingerprint_Check(b *testing.B) { addAttr(b, m, addr) addAttr(b, m, s) m.WriteHeader() - Fingerprint.AddTo(m) + Fingerprint.AddTo(m) //nolint: errcheck m.WriteHeader() b.SetBytes(int64(len(m.Raw))) for i := 0; i < b.N; i++ { diff --git a/helpers_test.go b/helpers_test.go index 771e485..c6fd456 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -19,14 +19,14 @@ func BenchmarkBuildOverhead(b *testing.B) { b.ReportAllocs() m := new(Message) for i := 0; i < b.N; i++ { - m.Build(&t, &username, &nonce, &realm, &Fingerprint) + m.Build(&t, &username, &nonce, &realm, &Fingerprint) //nolint: errcheck } }) b.Run("BuildNonPointer", func(b *testing.B) { b.ReportAllocs() m := new(Message) for i := 0; i < b.N; i++ { - m.Build(t, username, nonce, realm, Fingerprint) + m.Build(t, username, nonce, realm, Fingerprint) //nolint: errcheck //nolint: errcheck } }) b.Run("Raw", func(b *testing.B) { @@ -36,10 +36,10 @@ func BenchmarkBuildOverhead(b *testing.B) { m.Reset() m.WriteHeader() m.SetType(t) - username.AddTo(m) - nonce.AddTo(m) - realm.AddTo(m) - Fingerprint.AddTo(m) + username.AddTo(m) //nolint: errcheck + nonce.AddTo(m) //nolint: errcheck + realm.AddTo(m) //nolint: errcheck + Fingerprint.AddTo(m) //nolint: errcheck } }) } diff --git a/integrity_test.go b/integrity_test.go index c19467c..0ef16a4 100644 --- a/integrity_test.go +++ b/integrity_test.go @@ -21,7 +21,7 @@ func TestMessageIntegrity_AddTo_Simple(t *testing.T) { if err := i.AddTo(m); err != nil { t.Error(err) } - NewSoftware("software").AddTo(m) + NewSoftware("software").AddTo(m) //nolint: errcheck m.WriteHeader() dM := new(Message) dM.Raw = m.Raw @@ -42,7 +42,7 @@ func TestMessageIntegrityWithFingerprint(t *testing.T) { m := new(Message) m.TransactionID = [TransactionIDSize]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} m.WriteHeader() - NewSoftware("software").AddTo(m) + NewSoftware("software").AddTo(m) //nolint: errcheck i := NewShortTermIntegrity("pwd") if i.String() != "KEY: 0x707764" { t.Error("bad string", i) @@ -81,7 +81,7 @@ func TestMessageIntegrity(t *testing.T) { func TestMessageIntegrityBeforeFingerprint(t *testing.T) { m := new(Message) m.WriteHeader() - Fingerprint.AddTo(m) + Fingerprint.AddTo(m) //nolint: errcheck i := NewShortTermIntegrity("password") if err := i.AddTo(m); err == nil { t.Error("should error") @@ -106,7 +106,7 @@ func BenchmarkMessageIntegrity_Check(b *testing.B) { m := new(Message) // TODO: Find a way to make this test zero-alloc without excessive pre-alloc. m.Raw = make([]byte, 0, 1024) - NewSoftware("software").AddTo(m) + NewSoftware("software").AddTo(m) //nolint: errcheck integrity := NewShortTermIntegrity("password") b.ReportAllocs() m.WriteHeader() diff --git a/internal/hmac/hmac.go b/internal/hmac/hmac.go index 801ece6..14af942 100644 --- a/internal/hmac/hmac.go +++ b/internal/hmac/hmac.go @@ -45,8 +45,8 @@ func (h *hmac) Sum(in []byte) []byte { origLen := len(in) in = h.inner.Sum(in) h.outer.Reset() - h.outer.Write(h.opad) - h.outer.Write(in[origLen:]) + h.outer.Write(h.opad) //nolint: errcheck + h.outer.Write(in[origLen:]) //nolint: errcheck return h.outer.Sum(in[:origLen]) } @@ -60,7 +60,7 @@ func (h *hmac) BlockSize() int { return h.blocksize } func (h *hmac) Reset() { h.inner.Reset() - h.inner.Write(h.ipad) + h.inner.Write(h.ipad) //nolint: errcheck } // New returns a new HMAC hash using the given hash.Hash type and key. @@ -77,7 +77,7 @@ func New(h func() hash.Hash, key []byte) hash.Hash { hm.opad = make([]byte, hm.blocksize) if len(key) > hm.blocksize { // If key is too big, hash it. - hm.outer.Write(key) + hm.outer.Write(key) //nolint: errcheck key = hm.outer.Sum(nil) } copy(hm.ipad, key) @@ -88,7 +88,7 @@ func New(h func() hash.Hash, key []byte) hash.Hash { for i := range hm.opad { hm.opad[i] ^= 0x5c } - hm.inner.Write(hm.ipad) + hm.inner.Write(hm.ipad) //nolint: errcheck return hm } diff --git a/internal/hmac/hmac_test.go b/internal/hmac/hmac_test.go index eea345e..c655576 100644 --- a/internal/hmac/hmac_test.go +++ b/internal/hmac/hmac_test.go @@ -575,7 +575,7 @@ func BenchmarkHMACSHA256_1K(b *testing.B) { h := New(sha256.New, key) b.SetBytes(int64(len(buf))) for i := 0; i < b.N; i++ { - h.Write(buf) + h.Write(buf) //nolint: errcheck h.Reset() mac := h.Sum(nil) buf[0] = mac[0] @@ -588,7 +588,7 @@ func BenchmarkHMACSHA256_32(b *testing.B) { h := New(sha256.New, key) b.SetBytes(int64(len(buf))) for i := 0; i < b.N; i++ { - h.Write(buf) + h.Write(buf) //nolint: errcheck h.Reset() mac := h.Sum(nil) buf[0] = mac[0] diff --git a/internal/hmac/pool.go b/internal/hmac/pool.go index 4db61e5..20507ba 100644 --- a/internal/hmac/pool.go +++ b/internal/hmac/pool.go @@ -23,7 +23,7 @@ func (h *hmac) resetTo(key []byte) { setZeroes(h.opad) if len(key) > h.blocksize { // If key is too big, hash it. - h.outer.Write(key) + h.outer.Write(key) //nolint: errcheck key = h.outer.Sum(nil) } copy(h.ipad, key) @@ -34,7 +34,7 @@ func (h *hmac) resetTo(key []byte) { for i := range h.opad { h.opad[i] ^= 0x5c } - h.inner.Write(h.ipad) + h.inner.Write(h.ipad) //nolint: errcheck } var hmacSHA1Pool = &sync.Pool{ diff --git a/internal/hmac/pool_test.go b/internal/hmac/pool_test.go index 22bed95..75f912a 100644 --- a/internal/hmac/pool_test.go +++ b/internal/hmac/pool_test.go @@ -14,7 +14,7 @@ func BenchmarkHMACSHA1_512(b *testing.B) { h := AcquireSHA1(key) b.SetBytes(int64(len(buf))) for i := 0; i < b.N; i++ { - h.Write(buf) + h.Write(buf) //nolint: errcheck h.Reset() mac := h.Sum(nil) buf[0] = mac[0] @@ -29,7 +29,7 @@ func BenchmarkHMACSHA1_512_Pool(b *testing.B) { b.SetBytes(int64(len(buf))) for i := 0; i < b.N; i++ { h := AcquireSHA1(key) - h.Write(buf) + h.Write(buf) //nolint: errcheck h.Reset() mac := h.Sum(tBuf) buf[0] = mac[0] diff --git a/message_test.go b/message_test.go index ed9471b..8353080 100644 --- a/message_test.go +++ b/message_test.go @@ -263,7 +263,7 @@ func BenchmarkMessage_WriteTo(b *testing.B) { buf := new(bytes.Buffer) b.ReportAllocs() for i := 0; i < b.N; i++ { - m.WriteTo(buf) + m.WriteTo(buf) //nolint: errcheck buf.Reset() } } @@ -499,7 +499,7 @@ func TestMessage_String(t *testing.T) { func TestIsMessage(t *testing.T) { m := New() - NewSoftware("software").AddTo(m) + NewSoftware("software").AddTo(m) //nolint: errcheck m.WriteHeader() var tt = [...]struct { @@ -526,7 +526,7 @@ func BenchmarkIsMessage(b *testing.B) { m := New() m.Type = MessageType{Method: MethodBinding, Class: ClassRequest} m.TransactionID = NewTransactionID() - NewSoftware("cydev/stun test").AddTo(m) + NewSoftware("cydev/stun test").AddTo(m) //nolint: errcheck m.WriteHeader() b.SetBytes(int64(messageHeaderSize)) @@ -625,7 +625,7 @@ func BenchmarkMessageFull(b *testing.B) { addAttr(b, m, &s) m.WriteAttributes() m.WriteHeader() - Fingerprint.AddTo(m) + Fingerprint.AddTo(m) //nolint: errcheck m.WriteHeader() m.Reset() } @@ -679,7 +679,7 @@ func TestMessage_Contains(t *testing.T) { func ExampleMessage() { buf := new(bytes.Buffer) m := new(Message) - m.Build(BindingRequest, + m.Build(BindingRequest, //nolint: errcheck NewTransactionIDSetter([TransactionIDSize]byte{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, }), @@ -705,11 +705,11 @@ func ExampleMessage() { decoded.Raw = make([]byte, 0, 1024) // for ReadFrom that reuses m.Raw // ReadFrom does not allocate internal buffer for reading from io.Reader, // instead it uses m.Raw, expanding it length to capacity. - decoded.ReadFrom(buf) + decoded.ReadFrom(buf) //nolint: errcheck fmt.Println("has software:", decoded.Contains(AttrSoftware)) fmt.Println("has nonce:", decoded.Contains(AttrNonce)) var software Software - decoded.Parse(&software) // or software.GetFrom(decoded) + decoded.Parse(&software) //nolint: errcheck // Rule for Parse method is same as for Build. fmt.Println("software:", software) if err := Fingerprint.Check(decoded); err == nil { @@ -888,7 +888,7 @@ func BenchmarkMessage_CloneTo(b *testing.B) { } b.SetBytes(int64(len(m.Raw))) a := new(Message) - m.CloneTo(a) + m.CloneTo(a) //nolint: errcheck for i := 0; i < b.N; i++ { if err := m.CloneTo(a); err != nil { b.Fatal(err) @@ -917,7 +917,7 @@ func TestMessage_AddTo(t *testing.T) { if b.Equal(m) { t.Fatal("should not be equal") } - m.AddTo(b) + m.AddTo(b) //nolint: errcheck if !b.Equal(m) { t.Fatal("should be equal") } @@ -935,7 +935,7 @@ func BenchmarkMessage_AddTo(b *testing.B) { b.Fatal(err) } a := new(Message) - m.CloneTo(a) + m.CloneTo(a) //nolint: errcheck for i := 0; i < b.N; i++ { if err := m.AddTo(a); err != nil { b.Fatal(err) diff --git a/textattrs_test.go b/textattrs_test.go index 46292dc..b253cd9 100644 --- a/textattrs_test.go +++ b/textattrs_test.go @@ -72,7 +72,7 @@ func BenchmarkUsername_AddTo(b *testing.B) { func BenchmarkUsername_GetFrom(b *testing.B) { b.ReportAllocs() m := new(Message) - Username("test").AddTo(m) + Username("test").AddTo(m) //nolint: errcheck var u Username b.ResetTimer() for i := 0; i < b.N; i++ { @@ -258,8 +258,8 @@ func BenchmarkNonce_GetFrom(b *testing.B) { b.ReportAllocs() m := New() n := NewNonce("nonce") - n.AddTo(m) + n.AddTo(m) //nolint: errcheck for i := 0; i < b.N; i++ { - n.GetFrom(m) + n.GetFrom(m) //nolint: errcheck } } diff --git a/xoraddr_test.go b/xoraddr_test.go index 47b36fb..094f2f3 100644 --- a/xoraddr_test.go +++ b/xoraddr_test.go @@ -18,7 +18,7 @@ func BenchmarkXORMappedAddress_AddTo(b *testing.B) { ip := net.ParseIP("192.168.1.32") for i := 0; i < b.N; i++ { addr := &XORMappedAddress{IP: ip, Port: 3654} - addr.AddTo(m) + addr.AddTo(m) //nolint: errcheck m.Reset() } } @@ -105,7 +105,7 @@ func TestXORMappedAddress_GetFrom_Invalid(t *testing.T) { addr.IP = expectedIP addr.Port = expectedPort - addr.AddTo(m) + addr.AddTo(m) //nolint: errcheck m.WriteHeader() mRes := New() @@ -163,7 +163,7 @@ func TestXORMappedAddress_AddTo_IPv6(t *testing.T) { IP: net.ParseIP("fe80::dc2b:44ff:fe20:6009"), Port: 21254, } - addr.AddTo(m) + addr.AddTo(m) //nolint: errcheck m.WriteHeader() mRes := New()