Skip to content

Commit

Permalink
dev: some maint updates
Browse files Browse the repository at this point in the history
- update go to 1.22 (include formating)
- update linter to 1.57 (include fixes)
- simplify builds (go version)
  • Loading branch information
spali committed Apr 17, 2024
1 parent d8133bf commit 1fa7294
Show file tree
Hide file tree
Showing 32 changed files with 131 additions and 102 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 15 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
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.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
Expand Down Expand Up @@ -39,13 +50,11 @@ linters:
- revive
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck

# don't enable:
# - whitespace
Expand Down
16 changes: 15 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions cmd/e3dc/e3dc_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"strings"

Expand Down Expand Up @@ -112,15 +112,15 @@ 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)
} else {
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)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/e3dc/json_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/spali/go-rscp

go 1.19
go 1.22

require (
github.com/alvaroloes/enumer v1.1.2
Expand All @@ -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
)
27 changes: 10 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
3 changes: 2 additions & 1 deletion rscp/authlevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion rscp/authlevel_enumer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions rscp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion rscp/client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion rscp/client_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 13 additions & 12 deletions rscp/constants.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rscp/crypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion rscp/datatype_enumer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rscp/datatype_length.go
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading

0 comments on commit 1fa7294

Please sign in to comment.