From f6ea67b88c1f8157472123ca5f695891619fd4a0 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sun, 15 Feb 2026 16:02:07 +0000 Subject: [PATCH] enable revive linter --- .golangci.yml | 2 +- cmd/q3rcon-proxy/main.go | 3 ++- udpproxy.go | 13 ++++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 829f043..7c86c25 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,7 +6,7 @@ run: go: '1.24' linters: - disable: [errcheck, godot, misspell, revive] + disable: [errcheck, godot, misspell] enable: # Default enabled linters - errcheck # Check for unchecked errors diff --git a/cmd/q3rcon-proxy/main.go b/cmd/q3rcon-proxy/main.go index 63d442f..2ebf700 100644 --- a/cmd/q3rcon-proxy/main.go +++ b/cmd/q3rcon-proxy/main.go @@ -1,3 +1,4 @@ +// Package main implements a command-line application for a Quake 3 RCON proxy server. package main import ( @@ -44,7 +45,7 @@ func main() { Usage: "Proxy and target ports (proxy:target)", Sources: cli.EnvVars("Q3RCON_PORTS_MAPPING"), Required: true, - Action: func(ctx context.Context, cmd *cli.Command, v string) error { + Action: func(_ context.Context, _ *cli.Command, v string) error { // Validate the ports mapping for mapping := range strings.SplitSeq(v, ";") { ports := strings.Split(mapping, ":") diff --git a/udpproxy.go b/udpproxy.go index df43756..64988a7 100644 --- a/udpproxy.go +++ b/udpproxy.go @@ -1,12 +1,16 @@ +// Package udpproxy implements a simple UDP proxy server that forwards rcon and query packets between clients and a target server. package udpproxy import ( + "fmt" "net" "time" log "github.com/sirupsen/logrus" ) +// Client represents a UDP proxy server that forwards rcon and query packets between clients and a target server. +// It maintains a session cache to manage client sessions and handles packet forwarding between clients and the target server. type Client struct { laddr *net.UDPAddr raddr *net.UDPAddr @@ -17,15 +21,16 @@ type Client struct { sessionTimeout time.Duration } +// New creates a new Client with the specified proxy and target addresses, and applies any provided options. func New(proxy, target string, options ...Option) (*Client, error) { laddr, err := net.ResolveUDPAddr("udp", proxy) if err != nil { - return nil, err + return nil, fmt.Errorf("invalid proxy address: %w", err) } raddr, err := net.ResolveUDPAddr("udp", target) if err != nil { - return nil, err + return nil, fmt.Errorf("invalid target address: %w", err) } c := &Client{ @@ -42,11 +47,13 @@ func New(proxy, target string, options ...Option) (*Client, error) { return c, nil } +// ListenAndServe starts the UDP proxy server and listens for incoming packets from clients. +// It reads packets from the proxy connection, checks for existing sessions, and forwards packets to the target server. func (c *Client) ListenAndServe() error { var err error c.proxyConn, err = net.ListenUDP("udp", c.laddr) if err != nil { - return err + return fmt.Errorf("failed to listen on proxy address: %w", err) } go c.pruneSessions()