enable revive linter

This commit is contained in:
2026-02-15 16:02:07 +00:00
parent d18834b290
commit f6ea67b88c
3 changed files with 13 additions and 5 deletions

View File

@@ -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()