Skip to content

Commit

Permalink
Update golang, linter and add fixes fer new linter rules
Browse files Browse the repository at this point in the history
  • Loading branch information
outdead committed Nov 15, 2024
1 parent ca45b68 commit 5570c3e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 60 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version: 1.21.6
go-version: 1.23.3

- name: Check out code into the Go module directory
uses: actions/checkout@v4
Expand All @@ -27,7 +27,7 @@ jobs:
uses: golangci/golangci-lint-action@v3
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
version: v1.62.0

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
58 changes: 8 additions & 50 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
run:
skip-dirs:
- vendor/
skip-files:
- ".*_test.go$"

output:
format: colored-line-number
formats:
- format: colored-line-number
print-issued-lines: true
print-linter-name: true

Expand Down Expand Up @@ -57,32 +52,8 @@ linters-settings:
# put imports beginning with prefix after 3rd-party packages;
# it's a comma-separated list of prefixes
local-prefixes: github.com/golangci/golangci-lint
golint:
# minimal confidence for issues, default is 0.8
min-confidence: 0
gomnd:
settings:
mnd:
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks: argument,case,condition,operation,return,assign
govet:
# report about shadowed variables.
check-shadowing: true
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/Sirupsen/logrus
- gopkg.in/sirupsen/logrus.v0
- gopkg.in/sirupsen/logrus.v1
- gopkg.in/Sirupsen/logrus.v0
- gopkg.in/Sirupsen/logrus.v1
lll:
line-length: 120 # 120 is default
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
misspell:
locale: US
nakedret:
Expand All @@ -94,12 +65,6 @@ linters-settings:
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
unused:
# treat code as a program (not a library) and report unused exported identifiers; default is false.
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
Expand Down Expand Up @@ -167,30 +132,23 @@ linters-settings:
linters:
enable-all: true
disable:
- 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
- exportloopref # is deprecated (since v1.60.2)
- dupword
- gomnd
- wrapcheck
- exhaustruct # mad linter
- depguard
- mnd

issues:
exclude:
- "don't use ALL_CAPS in Go names; use CamelCase" # golint
- "ST1003: should not use ALL_CAPS in Go names; use CamelCase instead" # stylecheck
- "shadow: declaration of \"err\"" # govet
- "DefaultSettings`? is a global variable" # gochecknoglobals
- "are|is missing in" # exhaustivestruct # v1.33
exclude-dirs:
- vendor/
exclude-files:
- ".*_test.go$"
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [v1.3.6] - 2024-11-16
### Fixed
- Minor fixes in packet package.
- Fixed Go Coverage badge.

### Updated
- Updated Golang to 1.23.3 version.
- Updated golangci linter to 1.62.0 version.

### Added
- Added `Open` function as `Dial` alternative for create RCON connection with an existing net.Conn connection.

## [v1.3.5] - 2024-02-03
### Updated
- Updated Golang to 1.21.6 version.
Expand Down Expand Up @@ -98,7 +110,8 @@ changed.
### Added
- Initial implementation.

[Unreleased]: https://github.com/gorcon/rcon/compare/v1.3.5...HEAD
[Unreleased]: https://github.com/gorcon/rcon/compare/v1.3.6...HEAD
[v1.3.6]: https://github.com/gorcon/rcon/compare/v1.3.5...v1.3.6
[v1.3.5]: https://github.com/gorcon/rcon/compare/v1.3.4...v1.3.5
[v1.3.4]: https://github.com/gorcon/rcon/compare/v1.3.3...v1.3.4
[v1.3.3]: https://github.com/gorcon/rcon/compare/v1.3.2...v1.3.3
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/gorcon/rcon

go 1.21
go 1.23
12 changes: 6 additions & 6 deletions packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewPacket(packetType int32, packetID int32, body string) *Packet {
size := len([]byte(body)) + int(PacketHeaderSize+PacketPaddingSize)

return &Packet{
Size: int32(size),
Size: int32(size), //nolint:gosec // No matter
Type: packetType,
ID: packetID,
body: []byte(body),
Expand Down Expand Up @@ -119,19 +119,19 @@ func (packet *Packet) ReadFrom(r io.Reader) (int64, error) {
// response to a SERVERDATA_RESPONSE_VALUE packet.
packet.body = make([]byte, packet.Size-PacketHeaderSize)

var i int32
for i < packet.Size-PacketHeaderSize {
var i int64
for i < int64(packet.Size-PacketHeaderSize) {
var m int
var err error

if m, err = r.Read(packet.body[i:]); err != nil {
return n + int64(m) + int64(i), fmt.Errorf("rcon: %w", err)
return n + int64(m) + i, fmt.Errorf("rcon: %w", err)
}

i += int32(m)
i += int64(m)
}

n += int64(i)
n += i

// Remove null terminated strings from response body.
if !bytes.Equal(packet.body[len(packet.body)-int(PacketPaddingSize):], []byte{0x00, 0x00}) {
Expand Down
3 changes: 3 additions & 0 deletions rcon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ func TestConn_Execute(t *testing.T) {
* banid : Ban a SteamID. Use /banid SteamID
* banuser : Ban a user. Add a -ip to also ban the IP. Add a -r "reason" to specify a reason for the ban. Use: /banuser "username" -ip -r "reason". For example: /banuser "rj" -ip -r "spawn kill"
* changeoption : Change a server option. Use: /changeoption optionName "newValue"
* checkModsNeedUpdate : Indicates whether a mod has been updated. Writes answer to log file
* chopper : Place a helicopter event on a random player
* createhorde : Spawn a horde near a player. Use : /createhorde count "username". Example /createhorde 150 "rj" Username is optional except from the server console. With no username the horde will be created around you
* createhorde2 : UI_ServerOptionDesc_CreateHorde2
Expand All @@ -338,6 +339,7 @@ func TestConn_Execute(t *testing.T) {
* invisible : Make a player invisible to zombies. If no username is set then you will become invisible yourself. Use: /invisible "username" -value, ex /invisible "rj" -true (could be -false)
* kick : Kick a user. Add a -r "reason" to specify a reason for the kick. Use: /kickuser "username" -r "reason"
* lightning : Use /lightning "username", username is optional except from the server console
* log : Set log level. Use /log %1 %2
* noclip : Makes a player pass through walls and structures. Toggles with no value. Use: /noclip "username" -value. Example /noclip "rj" -true (could be -false)
* players : List all connected players
* quit : Save and quit the server
Expand All @@ -353,6 +355,7 @@ func TestConn_Execute(t *testing.T) {
* showoptions : Show the list of current server options and values.
* startrain : Starts raining on the server. Use /startrain "intensity", optional intensity is from 1 to 100
* startstorm : Starts a storm on the server. Use /startstorm "duration", optional duration is in game hours
* stats : Set and clear server statistics. Use /stats none|file|console|all period. Example /stats file 10
* stoprain : Stop raining on the server
* stopweather : Stop weather on the server
* teleport : Teleport to a player. Once teleported, wait for the map to appear. Use /teleport "playername" or /teleport "player1" "player2". Example /teleport "rj" or /teleport "rj" "toUser"
Expand Down

0 comments on commit 5570c3e

Please sign in to comment.