Skip to content

Commit

Permalink
Some linter fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmacdonald committed Feb 22, 2024
1 parent b817ab6 commit 79363a5
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 70 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ linters:
- gocritic
- gocyclo
- godot
- godox
#- godox
- goerr113
- gofmt
- gofumpt
Expand Down Expand Up @@ -91,7 +91,7 @@ linters:
- typecheck
- unconvert
- unparam
- unused
#- unused
- usestdlibvars
#- varnamelen
- wastedassign
Expand Down
7 changes: 4 additions & 3 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"context"
"errors"
"fmt"
"github.com/leighmacdonald/bd/rules"
"github.com/leighmacdonald/bd/store"
"github.com/leighmacdonald/steamid/v3/steamid"
"log/slog"
"os"
"sort"
"time"

"github.com/leighmacdonald/bd/rules"
"github.com/leighmacdonald/bd/store"
"github.com/leighmacdonald/steamid/v3/steamid"
)

// unMark will unmark & remove a player from your local list. This *will not* unmark players from any
Expand Down
3 changes: 2 additions & 1 deletion announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package main
import (
"context"
"fmt"
"github.com/leighmacdonald/bd/rules"
"log/slog"
"strings"
"time"

"github.com/leighmacdonald/bd/rules"
)

type announceHandler struct {

Check failure on line 13 in announce.go

View workflow job for this annotation

GitHub Actions / staticcheck

type announceHandler is unused (U1000)

Check failure on line 13 in announce.go

View workflow job for this annotation

GitHub Actions / staticcheck

type announceHandler is unused (U1000)
Expand Down
12 changes: 7 additions & 5 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/leighmacdonald/bd/store"
"log/slog"
"net/http"
"net/url"
Expand All @@ -14,6 +13,7 @@ import (
"time"

"github.com/leighmacdonald/bd-api/models"
"github.com/leighmacdonald/bd/store"
"github.com/leighmacdonald/steamid/v3/steamid"
"github.com/leighmacdonald/steamweb/v2"
)
Expand Down Expand Up @@ -107,12 +107,12 @@ func createLocalDataSource(key string) (*LocalDataSource, error) {
return &LocalDataSource{}, nil
}

func newDataSource(userSettings userSettings) (DataSource, error) {
func newDataSource(userSettings userSettings) (DataSource, error) { //nolint:ireturn
if userSettings.BdAPIEnabled {
return createAPIDataSource(userSettings.BdAPIAddress)
} else {
return createLocalDataSource(userSettings.APIKey)
}

return createLocalDataSource(userSettings.APIKey)
}

// steamIDStringList transforms a steamid.Collection into a comma separated list of SID64 strings.
Expand Down Expand Up @@ -318,7 +318,9 @@ func (p profileUpdater) applyRemoteData(data updatedRemoteData) {

if ban.VACBanned {
since := time.Now().AddDate(0, 0, -ban.DaysSinceLastBan)
player.LastVacBanOn.Scan(since)
if err := player.LastVacBanOn.Scan(since); err != nil {
slog.Error("failed to scan last vac ban", errAttr(err))
}
}

break
Expand Down
10 changes: 5 additions & 5 deletions discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ func (d discordState) discordUpdateActivity() error {
state := "Offline"

// TODO
//if inGame {
// state = "In-Game"
//}
// if inGame {
// state = "In-Game"
// }

details := "Idle"
if server.ServerName != "" {
Expand All @@ -246,9 +246,9 @@ func (d discordState) discordUpdateActivity() error {
SmallImage: "logo_cd",
SmallText: "",
Party: party,
//Timestamps: &client.Timestamps{
// Timestamps: &client.Timestamps{
// Start: &startupTime,
//},
// },
Buttons: buttons,
}); errSetActivity != nil {
return errors.Join(errSetActivity, errDiscordActivity)
Expand Down
22 changes: 9 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,18 @@ func run() int {
slog.String("commit", versionInfo.Commit),
slog.String("via", versionInfo.BuiltBy))

db, dbCloser, errDb := store.CreateDb(settingsMgr.DBPath())
if errDb != nil {
slog.Error("failed to create database", errAttr(errDb))
db, dbCloser, errDB := store.CreateDB(settingsMgr.DBPath())
if errDB != nil {
slog.Error("failed to create database", errAttr(errDB))
return 1
}
defer dbCloser()

//fsCache, cacheErr := NewCache(settingsMgr.ConfigRoot(), DurationCacheTimeout)
//if cacheErr != nil {
// slog.Error("Failed to setup cache", errAttr(cacheErr))
// return 1
//}
// fsCache, cacheErr := NewCache(settingsMgr.ConfigRoot(), DurationCacheTimeout)
// if cacheErr != nil {
// slog.Error("Failed to setup cache", errAttr(cacheErr))
// return 1
// }

logChan := make(chan string)

Expand Down Expand Up @@ -211,11 +211,7 @@ func run() int {
slog.Error("failed to create http handlers", errAttr(errRoutes))
}

httpServer, errWeb := newHTTPServer(rootCtx, settings.HTTPListenAddr, mux)

if errWeb != nil {
slog.Error("Failed to initialize http server", errAttr(errWeb))
}
httpServer := newHTTPServer(rootCtx, settings.HTTPListenAddr, mux)

go testLogFeeder(logChan)

Expand Down
23 changes: 12 additions & 11 deletions platform/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ package platform
import (
"errors"
"fmt"
"github.com/leighmacdonald/bd/frontend"
"github.com/mitchellh/go-homedir"
"github.com/mitchellh/go-ps"
"github.com/pkg/browser"
"log/slog"
"os/exec"
"path"
"strings"

"github.com/leighmacdonald/bd/frontend"
"github.com/mitchellh/go-homedir"
"github.com/mitchellh/go-ps"
"github.com/pkg/browser"
)

type LinuxPlatform struct {
Expand All @@ -25,7 +26,7 @@ type LinuxPlatform struct {
func New() LinuxPlatform {
// We cant really auto-detect this stuff in the same manner as on windows with the registry
// so linux users may need to configure this manually if .
var knownInstallLocations = []string{
knownInstallLocations := []string{
"~/.local/share/Steam", // Standard location
"~/.steam/steam/Steam",
}
Expand Down Expand Up @@ -72,13 +73,13 @@ func (l LinuxPlatform) LaunchTF2(steamRoot string, args []string) error {
// return errBin
//}

//steamBin := path.Join(steamRoot, "steamapps/common/Team Fortress 2/hl2.sh")
// steamBin := path.Join(steamRoot, "steamapps/common/Team Fortress 2/hl2.sh")

//fa := []string{steamBin, "-applaunch", "440"}
//fa := []string{steamBin}
//fa = append(fa, args...)
//slog.Debug(fmt.Sprintf("calling %s %s", steamBin, strings.Join(fa, " ")))
//cmd := exec.Command("/bin/bash", fa...)
// fa := []string{steamBin, "-applaunch", "440"}
// fa := []string{steamBin}
// fa = append(fa, args...)
// slog.Debug(fmt.Sprintf("calling %s %s", steamBin, strings.Join(fa, " ")))
// cmd := exec.Command("/bin/bash", fa...)

if errLaunch := cmd.Run(); errLaunch != nil {
return errors.Join(errLaunch, ErrLaunchBinary)
Expand Down
2 changes: 1 addition & 1 deletion player.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"database/sql"
"errors"
"github.com/leighmacdonald/bd/store"
"log/slog"
"time"

"github.com/leighmacdonald/bd-api/models"
"github.com/leighmacdonald/bd/rules"
"github.com/leighmacdonald/bd/store"
"github.com/leighmacdonald/steamid/v3/steamid"
"github.com/leighmacdonald/steamweb/v2"
)
Expand Down
5 changes: 3 additions & 2 deletions process_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package main

import (
"context"
"github.com/leighmacdonald/bd/addons"
"github.com/leighmacdonald/bd/platform"
"log/slog"
"os"
"sync/atomic"
"time"

"github.com/leighmacdonald/bd/addons"
"github.com/leighmacdonald/bd/platform"
)

type processState struct {
Expand Down
3 changes: 2 additions & 1 deletion rcon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"errors"
"fmt"
"github.com/leighmacdonald/rcon/rcon"
"log/slog"
"time"

"github.com/leighmacdonald/rcon/rcon"
)

type rconConnection struct {
Expand Down
14 changes: 5 additions & 9 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,15 @@ func (sm *settingsManager) readDefaultOrCreate() (userSettings, error) {
if errRead != nil {
if errors.Is(errRead, errConfigNotFound) {
slog.Info("Creating default config")
defaultSettings, errNew := newSettings(sm.platform)
if errNew != nil {
return userSettings{}, errNew
}

defaultSettings := newSettings(sm.platform)
if errSave := sm.save(); errSave != nil {
return settings, errSave
}

return defaultSettings, nil
} else {
return userSettings{}, errRead
}

return userSettings{}, errRead
}

return settings, nil
Expand Down Expand Up @@ -347,7 +343,7 @@ type userSettings struct {
Rcon RCONConfig `yaml:"rcon" json:"rcon"`
}

func newSettings(plat platform.Platform) (userSettings, error) {
func newSettings(plat platform.Platform) userSettings {
settings := userSettings{
SteamID: "",
SteamDir: plat.DefaultSteamRoot(),
Expand Down Expand Up @@ -458,7 +454,7 @@ func newSettings(plat platform.Platform) (userSettings, error) {
Rcon: newRconConfig(false),
}

return settings, nil
return settings
}

func (s *userSettings) AddList(config *ListConfig) error {
Expand Down
13 changes: 6 additions & 7 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import (
"context"
"errors"
"fmt"
"github.com/leighmacdonald/bd/rules"
"github.com/leighmacdonald/bd/store"
"github.com/leighmacdonald/steamweb/v2"
"log/slog"
"net"
"strings"
"sync"
"time"

"github.com/leighmacdonald/bd/rules"
"github.com/leighmacdonald/bd/store"
"github.com/leighmacdonald/steamid/v3/steamid"
"github.com/leighmacdonald/steamweb/v2"
)

var errPlayerNotFound = errors.New("player not found")
Expand Down Expand Up @@ -74,7 +74,7 @@ func (state *playerState) update(updated Player) {
state.Lock()
defer state.Unlock()

valid := make([]Player, len(state.activePlayers))
var valid []Player //nolint:prealloc

for _, player := range state.activePlayers {
if player.SteamID == updated.SteamID {
Expand Down Expand Up @@ -146,15 +146,15 @@ func (state *playerState) checkPlayerState(ctx context.Context, db store.Querier

if validTeam == player.Team {
announcer.announceMatch(ctx, player, matchSteam)
//state.update(*player)
// state.update(*player)
}
} else if player.Personaname != "" {
if matchName := re.MatchName(player.Personaname); matchName != nil && validTeam == player.Team {
player.Matches = matchName

if validTeam == player.Team {
announcer.announceMatch(ctx, player, matchName)
//state.update(*player)
// state.update(*player)
}
}
}
Expand All @@ -168,7 +168,6 @@ func (state *playerState) checkPlayerState(ctx context.Context, db store.Querier

player.Dirty = false
}

}

type gameState struct {
Expand Down
9 changes: 5 additions & 4 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"embed"
"errors"
"fmt"
"log/slog"

"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/sqlite"
"github.com/golang-migrate/migrate/v4/source/iofs"
"log/slog"
)

//go:embed migrations/*.sql
Expand All @@ -25,13 +26,13 @@ var (
ErrPerformMigration = errors.New("failed to migrate database")
)

func CreateDb(dbPath string) (*Queries, func(), error) {
func CreateDB(dbPath string) (*Queries, func(), error) {
dbConn, errDB := Connect(dbPath)
if errDB != nil {
return nil, nil, errDB
}

var closer = func() {
closer := func() {
Close(dbConn)
}

Expand All @@ -43,7 +44,7 @@ func CreateDb(dbPath string) (*Queries, func(), error) {
}

func Connect(dsn string) (*sql.DB, error) {
dsn = dsn + "?cache=shared&mode=rwc"
dsn += "?cache=shared&mode=rwc"
database, errOpen := sql.Open("sqlite", dsn)
if errOpen != nil {
return nil, errors.Join(errOpen, ErrOpenDatabase)
Expand Down
5 changes: 3 additions & 2 deletions testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"context"
"fmt"
"math/rand"
"time"

"github.com/leighmacdonald/bd/rules"
"github.com/leighmacdonald/steamid/v3/steamid"
"github.com/leighmacdonald/steamweb/v2"
"math/rand"
"time"
)

type mkPlayerFunc func(ctx context.Context, sid64 steamid.SID64) (Player, error)
Expand Down
Loading

0 comments on commit 79363a5

Please sign in to comment.