From 1fa7294f9c730ecd558728f843a5f16b1bfa2c34 Mon Sep 17 00:00:00 2001 From: Thomas Spalinger Date: Wed, 17 Apr 2024 11:39:57 +0200 Subject: [PATCH] dev: some maint updates - update go to 1.22 (include formating) - update linter to 1.57 (include fixes) - simplify builds (go version) --- .github/workflows/build.yml | 15 ++++++------- .github/workflows/codeql.yml | 5 +++++ .github/workflows/prerelease.yml | 3 ++- .github/workflows/release.yml | 5 ++--- .golangci.yml | 21 +++++++++++++------ .vscode/tasks.json | 16 +++++++++++++- cmd/e3dc/e3dc_help.go | 6 +++--- cmd/e3dc/json_input.go | 2 +- go.mod | 7 ++++--- go.sum | 27 +++++++++--------------- rscp/authlevel.go | 3 ++- rscp/authlevel_enumer.go | 1 - rscp/client.go | 6 +++--- rscp/client_config.go | 3 ++- rscp/client_status.go | 3 ++- rscp/constants.go | 25 +++++++++++----------- rscp/crypt.go | 2 +- rscp/datatype_enumer.go | 1 - rscp/datatype_length.go | 3 ++- rscp/datatype_new.go | 36 ++++++++++++++++---------------- rscp/datatype_validate.go | 2 +- rscp/reader_test.go | 4 ++-- rscp/request.go | 14 +++++++------ rscp/rscperror.go | 5 +++-- rscp/rscperror_enumer.go | 1 - rscp/tag.go | 3 ++- rscp/tag_datatype.go | 5 +++-- rscp/tag_enumer.go | 1 - rscp/tag_issecret.go | 2 +- rscp/writer.go | 2 +- rscp/writer_test.go | 2 +- tools/tools.go | 2 +- 32 files changed, 131 insertions(+), 102 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3036e3a..ec084ee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,18 +15,19 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 6 steps: - - uses: actions/setup-go@v5 - with: - go-version: 1.17 - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + check-latest: true - name: Lint uses: golangci/golangci-lint-action@v4 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.47 + version: v1.57.2 args: --timeout 10m test: @@ -36,16 +37,16 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macOS-latest, windows-latest] - go: [1.17, 1.18, 1.19] steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - - name: "Setup Go ${{ matrix.go }}" + - name: "Setup Go" uses: actions/setup-go@v5 with: - go-version: "${{ matrix.go }}" + go-version-file: go.mod + check-latest: true - name: "Setup Go modules cache" uses: "actions/cache@v4" with: diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 6a629a0..4c91d63 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -25,6 +25,11 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + # workaround for https://github.com/github/codeql/issues/15647 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + check-latest: true - name: Initialize uses: github/codeql-action/init@v3 with: diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index 90ee3c9..5ec016d 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -19,7 +19,8 @@ jobs: - name: Install Go uses: actions/setup-go@v5 with: - go-version: ${{ env.GO_VERSION }} + go-version-file: go.mod + check-latest: true - name: Create release uses: goreleaser/goreleaser-action@v5 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 829a505..a03ed11 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,12 +14,11 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 # See: https://goreleaser.com/ci/actions/ - - name: Determine Go version from go.mod - run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV - name: Install Go uses: actions/setup-go@v5 with: - go-version: ${{ env.GO_VERSION }} + go-version-file: go.mod + check-latest: true - name: Create release uses: goreleaser/goreleaser-action@v5 with: diff --git a/.golangci.yml b/.golangci.yml index f87fa56..88bef09 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,9 +1,21 @@ -run: - go: '1.17' - linters-settings: lll: line-length: 140 + depguard: + rules: + main: + files: + - "$all" + - "!$test" + allow: + - "$gostd" + - github.com/ + tests: + files: + - "$test" + allow: + - "$gostd" + - github.com/ linters: # please, do not use `enable-all`: it's deprecated and will be removed soon. @@ -11,7 +23,6 @@ linters: disable-all: true enable: - bodyclose - - deadcode - depguard - dogsled - dupl @@ -39,13 +50,11 @@ linters: - revive - rowserrcheck - staticcheck - - structcheck - stylecheck - typecheck - unconvert - unparam - unused - - varcheck # don't enable: # - whitespace diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 1d69531..3c754b7 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,7 +6,21 @@ { "label": "Go Generate", "type": "shell", - "command": "PATH=$PATH:~/go/bin go generate ./...", + "command": "go generate ./...", + "presentation": { + "echo": true, + "reveal": "silent", + "focus": false, + "panel": "shared", + "showReuseMessage": true, + "clear": false + }, + "problemMatcher":"$go" + }, + { + "label": "Go lint", + "type": "shell", + "command": "golangci-lint run ./...", "presentation": { "echo": true, "reveal": "silent", diff --git a/cmd/e3dc/e3dc_help.go b/cmd/e3dc/e3dc_help.go index d9f62a7..c3ee3f1 100644 --- a/cmd/e3dc/e3dc_help.go +++ b/cmd/e3dc/e3dc_help.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - "io/ioutil" + "io" "os" "strings" @@ -112,7 +112,7 @@ func checkFlags(fs *flag.FlagSet) (*flag.FlagSet, error) { m []byte err error ) - if m, err = ioutil.ReadFile(conf.file); err != nil { + if m, err = os.ReadFile(conf.file); err != nil { return fs, fmt.Errorf("could not read input file: %s", err) } conf.request = string(m) @@ -120,7 +120,7 @@ func checkFlags(fs *flag.FlagSet) (*flag.FlagSet, error) { stat, _ := os.Stdin.Stat() if stdin := (stat.Mode() & os.ModeCharDevice) == 0; stdin { var bytes []byte - bytes, err := ioutil.ReadAll(os.Stdin) + bytes, err := io.ReadAll(os.Stdin) if err != nil { return fs, fmt.Errorf("could not read stdin: %s", err) } diff --git a/cmd/e3dc/json_input.go b/cmd/e3dc/json_input.go index f332f7f..63a7399 100644 --- a/cmd/e3dc/json_input.go +++ b/cmd/e3dc/json_input.go @@ -26,7 +26,7 @@ func unmarshalJSONValue(b []byte, m *rscp.Message) error { return nil } -//nolint: gomnd +//nolint:gomnd func unmarshalJSONRequest(b []byte, m *rscp.Message) error { if isJSONEmpty(b) { return ErrInputInvalidTuple diff --git a/go.mod b/go.mod index 8ffd8b0..c7d4548 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/spali/go-rscp -go 1.19 +go 1.22 require ( github.com/alvaroloes/enumer v1.1.2 @@ -14,6 +14,7 @@ require ( require ( github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1 // indirect - golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect - golang.org/x/tools v0.0.0-20190524210228-3d17549cdc6b // indirect + golang.org/x/mod v0.14.0 // indirect + golang.org/x/sys v0.16.0 // indirect + golang.org/x/tools v0.13.0 // indirect ) diff --git a/go.sum b/go.sum index 614ea85..641cbb9 100644 --- a/go.sum +++ b/go.sum @@ -2,15 +2,11 @@ github.com/alvaroloes/enumer v1.1.2 h1:5khqHB33TZy1GWCO/lZwcroBFh7u+0j40T83VUbfA github.com/alvaroloes/enumer v1.1.2/go.mod h1:FxrjvuXoDAx9isTJrv4c+T410zFi0DtXIT0m65DJ+Wo= github.com/azihsoyn/rijndael256 v0.0.0-20200316065338-d14eefa2b66b h1:/2dABok/UswXOj5rjbR5bZ411ApGBq1pAEZdy5rvFrY= github.com/azihsoyn/rijndael256 v0.0.0-20200316065338-d14eefa2b66b/go.mod h1:ef+2vMUkiKcy2Tz7HykB01KbgUnkK4gQKq4ZeR4RYVs= -github.com/cstockton/go-conv v0.0.0-20170524002450-66a2b2ba36e1 h1:h4OgDocdYHGiUh+zUEe4nFlb9ShoHUllqDefGaRoZFg= -github.com/cstockton/go-conv v0.0.0-20170524002450-66a2b2ba36e1/go.mod h1:MBKpQ5HV5wcT/nQYoEqjSMiXwxPouaReOs2f4kj70SQ= github.com/cstockton/go-conv v1.0.0 h1:zj/q/0MpQ/97XfiC9glWiohO8lhgR4TTnHYZifLTv6I= github.com/cstockton/go-conv v1.0.0/go.mod h1:HuiHkkRgOA0IoBNPC7ysG7kNpjDYlgM7Kj62yQPxjy4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM= -github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/jnovack/flag v1.16.0 h1:gJC3JVofq/hNGlNfki4NlIWLOiDkaeLNUOCzznCablU= @@ -19,31 +15,28 @@ github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1 h1:/I3lTljEEDNYL github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1/go.mod h1:eD5JxqMiuNYyFNmyY9rkJ/slN8y59oEu4Ei7F8OoKWQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= -github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= -github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/sirupsen/logrus v1.9.2 h1:oxx1eChJGI6Uks2ZC4W1zpLlVgqB8ner4EuQwV4Ik1Y= -github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spali/go-slicereader v0.0.0-20201122145524-8e262e1a5127 h1:YDqvwAH/l3S4ZULmKlUYszPyLBjHq73CLuUPU+2jJeE= github.com/spali/go-slicereader v0.0.0-20201122145524-8e262e1a5127/go.mod h1:nf5bOq6n8UugtmQiD3l0BzkE5VP4NvyngFZVkH3ZzgM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= +golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20190524210228-3d17549cdc6b h1:iEAPfYPbYbxG/2lNN4cMOHkmgKNsCuUwkxlDCK46UlU= golang.org/x/tools v0.0.0-20190524210228-3d17549cdc6b/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/rscp/authlevel.go b/rscp/authlevel.go index e00a861..9d58552 100644 --- a/rscp/authlevel.go +++ b/rscp/authlevel.go @@ -3,8 +3,9 @@ package rscp type AuthLevel uint8 // all auth levels as constant +// +//nolint:revive,stylecheck //go:generate go run github.com/alvaroloes/enumer -type=AuthLevel -json -//nolint: revive,stylecheck const ( AUTH_LEVEL_NO_AUTH AuthLevel = 0 AUTH_LEVEL_USER AuthLevel = 10 diff --git a/rscp/authlevel_enumer.go b/rscp/authlevel_enumer.go index 315b421..2c47647 100644 --- a/rscp/authlevel_enumer.go +++ b/rscp/authlevel_enumer.go @@ -1,6 +1,5 @@ // Code generated by "enumer -type=AuthLevel -json"; DO NOT EDIT. -// package rscp import ( diff --git a/rscp/client.go b/rscp/client.go index 089f01e..76bdd9a 100644 --- a/rscp/client.go +++ b/rscp/client.go @@ -80,14 +80,14 @@ func (c *Client) receive() ([]Message, error) { var dataSize uint16 var m []Message - for i, new := 0, make([]byte, uint32(RSCP_CRYPT_BLOCK_SIZE)*uint32(c.config.ReceiveBufferBlockSize)); ; { + for i, data := 0, make([]byte, uint32(RSCP_CRYPT_BLOCK_SIZE)*uint32(c.config.ReceiveBufferBlockSize)); ; { var err error - if i, err = c.conn.Read(new); err != nil { + if i, err = c.conn.Read(data); err != nil { return nil, fmt.Errorf("error during receive response: %w", err) } else if i == 0 { return nil, ErrRscpInvalidFrameLength } - switch m, err = Read(&c.decrypter, &buf, &crcFlag, &frameSize, &dataSize, new[:i]); { + switch m, err = Read(&c.decrypter, &buf, &crcFlag, &frameSize, &dataSize, data[:i]); { case errors.Is(err, ErrRscpInvalidFrameLength): // frame not complete continue diff --git a/rscp/client_config.go b/rscp/client_config.go index 094c9fb..35ce2c6 100644 --- a/rscp/client_config.go +++ b/rscp/client_config.go @@ -33,7 +33,8 @@ type ClientConfig struct { } // defaultClientConfig defines the default config values used when not provided by the user. -//nolint: gomnd +// +//nolint:gomnd var defaultClientConfig = ClientConfig{ Port: 5033, HeartbeatInterval: time.Second * 10, diff --git a/rscp/client_status.go b/rscp/client_status.go index 6c6276a..cff1f15 100644 --- a/rscp/client_status.go +++ b/rscp/client_status.go @@ -8,7 +8,8 @@ func (status ClientStatus) String() string { } // all errors as constant -//nolint: revive,stylecheck +// +//nolint:revive,stylecheck const ( STATUS_OK ClientStatus = 0 STATUS_ERR_INVALID_INPUT ClientStatus = -1 diff --git a/rscp/constants.go b/rscp/constants.go index d2340ac..5bf94b7 100644 --- a/rscp/constants.go +++ b/rscp/constants.go @@ -1,6 +1,6 @@ package rscp -//nolint: revive,stylecheck +//nolint:revive,stylecheck const ( RSCP_FRAME_MAGIC_SIZE uint16 = 0x2 // magic field size of frame RSCP_FRAME_CTRL_SIZE uint16 = 0x2 // control field size of frame @@ -34,18 +34,19 @@ const ( ) // control field of frame -// Byte | 0 | 1 | -// Bit | 7 6 5 4 3 2 1 0 | 7 6 5 4 3 2 1 0 | -// | R R R C V V V V | R R R R R R R R | -// | R R R | R R R R R R R R | Reserviert für zukünfige Erweiterungen -> RSCP_CTRL_BIT_MASK -// | 0 0 0 | 0 0 0 0 0 0 0 0 | Derzeitiger Zustand für die reservierten Bit -// | C | | Checksummen Flag -> RSCP_CTRL_BIT_MASK -// | 0 | | Checksumme wird nicht verwendet -// | 1 | | Checksumme wird verwendet. Das Feld CRC am Ende des Frames ist ein Pflichtfeld, ansonsten wird der Frame verworfen! -> RSCP_CRC_FLAG -// | V V V V | | Versionskennzeichnung -> RSCP_CTRL_BIT_MASK_VERSION -// | 0 0 0 1 | | Version 1.0 (Momentan einzig zugelassener Wert) -> RSCP_VERSION_1_0 // -//nolint: lll,revive,stylecheck +// Byte | 0 | 1 | +// Bit | 7 6 5 4 3 2 1 0 | 7 6 5 4 3 2 1 0 | +// | R R R C V V V V | R R R R R R R R | +// | R R R | R R R R R R R R | Reserviert für zukünfige Erweiterungen -> RSCP_CTRL_BIT_MASK +// | 0 0 0 | 0 0 0 0 0 0 0 0 | Derzeitiger Zustand für die reservierten Bit +// | C | | Checksummen Flag -> RSCP_CTRL_BIT_MASK +// | 0 | | Checksumme wird nicht verwendet +// | 1 | | Checksumme wird verwendet. Das Feld CRC am Ende des Frames ist ein Pflichtfeld, ansonsten wird der Frame verworfen! -> RSCP_CRC_FLAG +// | V V V V | | Versionskennzeichnung -> RSCP_CTRL_BIT_MASK_VERSION +// | 0 0 0 1 | | Version 1.0 (Momentan einzig zugelassener Wert) -> RSCP_VERSION_1_0 +// +//nolint:lll,revive,stylecheck const ( RSCP_CTRL_BIT_MASK_CRC uint16 = 0b0001000000000000 // allowed bit's for crc field of control field RSCP_FLAG_BIT_CRC uint8 = 12 // bit start position of crc field of control field diff --git a/rscp/crypt.go b/rscp/crypt.go index 430f63a..94e493c 100644 --- a/rscp/crypt.go +++ b/rscp/crypt.go @@ -6,7 +6,7 @@ import ( "github.com/azihsoyn/rijndael256" ) -//nolint: revive,stylecheck +//nolint:revive,stylecheck const ( RSCP_CRYPT_BLOCK_SIZE uint8 = rijndael256.BlockSize RSCP_CRYPT_BLOCK_PADDING = byte(0x00) diff --git a/rscp/datatype_enumer.go b/rscp/datatype_enumer.go index 1578711..be68472 100644 --- a/rscp/datatype_enumer.go +++ b/rscp/datatype_enumer.go @@ -1,6 +1,5 @@ // Code generated by "enumer -type=DataType -json"; DO NOT EDIT. -// package rscp import ( diff --git a/rscp/datatype_length.go b/rscp/datatype_length.go index 33d34bb..c302601 100644 --- a/rscp/datatype_length.go +++ b/rscp/datatype_length.go @@ -1,7 +1,8 @@ package rscp // defines the expected Length of the data type or 0 for variable length -//nolint: gomnd +// +//nolint:gomnd var lengthMap = map[DataType]uint16{ None: 0, Bool: 1, diff --git a/rscp/datatype_new.go b/rscp/datatype_new.go index 9309ef0..ca74243 100644 --- a/rscp/datatype_new.go +++ b/rscp/datatype_new.go @@ -9,28 +9,28 @@ import ( // returns pointer to new interface of the expected go type var newEmptyMap = map[DataType]func(size uint16) interface{}{ - None: func(size uint16) interface{} { return nil }, - Bool: func(size uint16) interface{} { return new(bool) }, - Char8: func(size uint16) interface{} { return new(int8) }, - UChar8: func(size uint16) interface{} { return new(uint8) }, - Int16: func(size uint16) interface{} { return new(int16) }, - UInt16: func(size uint16) interface{} { return new(uint16) }, - Int32: func(size uint16) interface{} { return new(int32) }, - Uint32: func(size uint16) interface{} { return new(uint32) }, - Int64: func(size uint16) interface{} { return new(int64) }, - Uint64: func(size uint16) interface{} { return new(uint64) }, - Float32: func(size uint16) interface{} { return new(float32) }, - Double64: func(size uint16) interface{} { return new(float64) }, + None: func(_ uint16) interface{} { return nil }, + Bool: func(_ uint16) interface{} { return new(bool) }, + Char8: func(_ uint16) interface{} { return new(int8) }, + UChar8: func(_ uint16) interface{} { return new(uint8) }, + Int16: func(_ uint16) interface{} { return new(int16) }, + UInt16: func(_ uint16) interface{} { return new(uint16) }, + Int32: func(_ uint16) interface{} { return new(int32) }, + Uint32: func(_ uint16) interface{} { return new(uint32) }, + Int64: func(_ uint16) interface{} { return new(int64) }, + Uint64: func(_ uint16) interface{} { return new(uint64) }, + Float32: func(_ uint16) interface{} { return new(float32) }, + Double64: func(_ uint16) interface{} { return new(float64) }, // TODO: currently no known tag returns this type, // so not sure if this is correct (BAT_REQ_STATUS_CODE and BAT_REQ_ERROR_CODE documented to return it, but thats wrong). - Bitfield: func(size uint16) interface{} { return new(byte) }, - CString: func(size uint16) interface{} { return new(string) }, - Container: func(size uint16) interface{} { return new([]Message) }, - Timestamp: func(size uint16) interface{} { return new(time.Time) }, + Bitfield: func(_ uint16) interface{} { return new(byte) }, + CString: func(_ uint16) interface{} { return new(string) }, + Container: func(_ uint16) interface{} { return new([]Message) }, + Timestamp: func(_ uint16) interface{} { return new(time.Time) }, // TODO: could not be tested, // couldn't get a request working for the only known Tag that should response with WB_EXTERN_DATA. ByteArray: func(size uint16) interface{} { return make([]byte, size) }, - Error: func(size uint16) interface{} { return new(RscpError) }, + Error: func(_ uint16) interface{} { return new(RscpError) }, } // newEmpty returns pointer to new interface of the expected go type @@ -40,7 +40,7 @@ func (d DataType) newEmpty(s uint16) interface{} { // returns pointer to new interface of the expected go type with the provided value var newMap = map[DataType]func(v interface{}) (interface{}, error){ - None: func(v interface{}) (interface{}, error) { return nil, nil }, + None: func(_ interface{}) (interface{}, error) { return nil, nil }, Bool: func(v interface{}) (interface{}, error) { return conv.Bool(v) }, Char8: func(v interface{}) (interface{}, error) { return conv.Uint8(v) }, UChar8: func(v interface{}) (interface{}, error) { return conv.Uint8(v) }, diff --git a/rscp/datatype_validate.go b/rscp/datatype_validate.go index 29e1cbc..d17af47 100644 --- a/rscp/datatype_validate.go +++ b/rscp/datatype_validate.go @@ -4,7 +4,7 @@ import ( "time" ) -// defines the expected Length of the data type or 0 for variable Length +// defines the expected Length of the data type or 0 for variable Length var validateMap = map[DataType]func(v interface{}) bool{ None: func(v interface{}) bool { return v == nil }, Bool: func(v interface{}) bool { _, isType := v.(bool); return isType }, diff --git a/rscp/reader_test.go b/rscp/reader_test.go index 0399b74..a43e2fb 100644 --- a/rscp/reader_test.go +++ b/rscp/reader_test.go @@ -157,7 +157,7 @@ func Test_truncatePadding(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - err := truncatePadding(&tt.args.data, tt.args.frameSize) + err := truncatePadding(&tt.args.data, tt.args.frameSize) // #nosec G601 if (err != nil || tt.wantErr != nil) && !errors.Is(err, tt.wantErr) { t.Errorf("truncatePadding() error = %v, wantErr %v", err, tt.wantErr) } @@ -519,7 +519,7 @@ func TestRead(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := Read(&tt.args.mode, tt.args.buf, tt.args.crcFlag, tt.args.frameSize, tt.args.dataSize, tt.args.data) + got, err := Read(&tt.args.mode, tt.args.buf, tt.args.crcFlag, tt.args.frameSize, tt.args.dataSize, tt.args.data) // #nosec G601 if (err != nil || tt.wantErr != nil) && !errors.Is(err, tt.wantErr) { t.Errorf("Read() error = %v, wantErr %v", err, tt.wantErr) } diff --git a/rscp/request.go b/rscp/request.go index c06afff..a3b50ff 100644 --- a/rscp/request.go +++ b/rscp/request.go @@ -28,9 +28,10 @@ func validateRequests(messages []Message) error { // if the tag's data type is a Container, following tag's will be nested as "sub" requests within the container. // Every tag that has a data type other than DATATYPE_None requires a following value. // Examples: -// CreateRequest(INFO_REQ_UTC_TIME) -// CreateRequest(EMS_REQ_SET_ERROR_BUZZER_ENABLED, true) -// CreateRequest(BAT_REQ_DATA, BAT_INDEX, 0, BAT_REQ_DEVICE_STATE, BAT_REQ_RSOC, BAT_REQ_STATUS_CODE) +// +// CreateRequest(INFO_REQ_UTC_TIME) +// CreateRequest(EMS_REQ_SET_ERROR_BUZZER_ENABLED, true) +// CreateRequest(BAT_REQ_DATA, BAT_INDEX, 0, BAT_REQ_DEVICE_STATE, BAT_REQ_RSOC, BAT_REQ_STATUS_CODE) func CreateRequest(values ...interface{}) (msg *Message, err error) { if msg, err = readRequestSlice(values); err != nil { return nil, err @@ -41,9 +42,10 @@ func CreateRequest(values ...interface{}) (msg *Message, err error) { // CreateRequests creates multiple new requests (infer the data type from the tag) // if the tag's data type is a Container, provided values will be converted to "sub" requests, separated by the provided tag's // Examples: -// CreateRequests([]interface{}{INFO_REQ_UTC_TIME}) -// CreateRequests([]interface{}{EMS_REQ_SET_ERROR_BUZZER_ENABLED, true}) -// CreateRequests([]interface{}{BAT_REQ_DATA, BAT_INDEX, 0, BAT_REQ_DEVICE_STATE, BAT_REQ_RSOC, BAT_REQ_STATUS_CODE}) +// +// CreateRequests([]interface{}{INFO_REQ_UTC_TIME}) +// CreateRequests([]interface{}{EMS_REQ_SET_ERROR_BUZZER_ENABLED, true}) +// CreateRequests([]interface{}{BAT_REQ_DATA, BAT_INDEX, 0, BAT_REQ_DEVICE_STATE, BAT_REQ_RSOC, BAT_REQ_STATUS_CODE}) func CreateRequests(values ...[]interface{}) ([]Message, error) { if len(values) == 0 { return nil, ErrNoArguments diff --git a/rscp/rscperror.go b/rscp/rscperror.go index 72cccf3..4d5d96e 100644 --- a/rscp/rscperror.go +++ b/rscp/rscperror.go @@ -1,11 +1,12 @@ package rscp -//nolint: revive +//nolint:revive type RscpError uint32 // all errors as constant +// +//nolint:revive,stylecheck //go:generate go run github.com/alvaroloes/enumer -type=RscpError -json -//nolint: revive,stylecheck const ( ERR_NOT_HANDLED RscpError = 0x01 ERR_ACCESS_DENIED RscpError = 0x02 diff --git a/rscp/rscperror_enumer.go b/rscp/rscperror_enumer.go index 713422e..70ec98f 100644 --- a/rscp/rscperror_enumer.go +++ b/rscp/rscperror_enumer.go @@ -1,6 +1,5 @@ // Code generated by "enumer -type=RscpError -json"; DO NOT EDIT. -// package rscp import ( diff --git a/rscp/tag.go b/rscp/tag.go index cd2f783..1e8568f 100644 --- a/rscp/tag.go +++ b/rscp/tag.go @@ -4,8 +4,9 @@ package rscp type Tag uint32 // all tags as constant +// +//nolint:revive,stylecheck //go:generate go run github.com/alvaroloes/enumer -type=Tag -json -//nolint: revive,stylecheck const ( // Dieser TAG kapselt eine Authorisierungsanfrage an das S10. // Er enthält daher die Daten-Tags AUTHENTICATION_USER und AUTHENTICATION_PASSWORD diff --git a/rscp/tag_datatype.go b/rscp/tag_datatype.go index 25fd1a6..a2e2548 100644 --- a/rscp/tag_datatype.go +++ b/rscp/tag_datatype.go @@ -1,7 +1,8 @@ package rscp -// defines the expected Length of the data type or 0 for variable length -//nolint: lll +// defines the expected Length of the data type or 0 for variable length +// +//nolint:lll var dataTypeMap = map[Tag]DataType{ RSCP_REQ_AUTHENTICATION: Container, RSCP_AUTHENTICATION_USER: CString, diff --git a/rscp/tag_enumer.go b/rscp/tag_enumer.go index 9d4acbd..0e9231c 100644 --- a/rscp/tag_enumer.go +++ b/rscp/tag_enumer.go @@ -1,6 +1,5 @@ // Code generated by "enumer -type=Tag -json"; DO NOT EDIT. -// package rscp import ( diff --git a/rscp/tag_issecret.go b/rscp/tag_issecret.go index 8b0342e..c3230d7 100644 --- a/rscp/tag_issecret.go +++ b/rscp/tag_issecret.go @@ -1,6 +1,6 @@ package rscp -// defines the expected Length of the data type or 0 for variable Length +// defines the expected Length of the data type or 0 for variable Length var secretTags = []Tag{ RSCP_AUTHENTICATION_PASSWORD, RSCP_REQ_SET_ENCRYPTION_PASSPHRASE, diff --git a/rscp/writer.go b/rscp/writer.go index b9ac40a..3b68139 100644 --- a/rscp/writer.go +++ b/rscp/writer.go @@ -37,7 +37,7 @@ func write(buf *bytes.Buffer, v interface{}) error { // not testable return err } - //nolint: gomnd + //nolint:gomnd if err := write(buf, int32(v.UnixNano()-(v.Unix()*1e9))); err != nil { // not testable return err diff --git a/rscp/writer_test.go b/rscp/writer_test.go index 9b8d32a..d6c867e 100644 --- a/rscp/writer_test.go +++ b/rscp/writer_test.go @@ -127,7 +127,7 @@ func TestWrite(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := Write(&tt.mode, tt.messages, tt.useChecksum) + got, err := Write(&tt.mode, tt.messages, tt.useChecksum) // #nosec G601 if (err != nil || tt.wantErr != nil) && !(errors.Is(err, tt.wantErr) || err.Error() == tt.wantErr.Error()) { t.Errorf("Write() error = %#v, wantErr %#v", err, tt.wantErr) } diff --git a/tools/tools.go b/tools/tools.go index cc4e88d..731def0 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -1,4 +1,4 @@ -// +build tools +//go:build tools package tools