ref(cmd/tcpfwd): simplify parseForward with strings.Cut

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
AJ ONeal 2026-02-27 22:12:02 -07:00
parent 3f16e89f5c
commit f9e06f131b
No known key found for this signature in database

View File

@ -44,11 +44,11 @@ type forward struct {
// parseForward parses a "local-port:remote-host:remote-port" string. // parseForward parses a "local-port:remote-host:remote-port" string.
func parseForward(s string) (forward, error) { func parseForward(s string) (forward, error) {
i := strings.Index(s, ":") localPort, target, ok := strings.Cut(s, ":")
if i < 0 || !strings.Contains(s[i+1:], ":") { if !ok || !strings.Contains(target, ":") {
return forward{}, fmt.Errorf("invalid forward %q: expected local-port:remote-host:remote-port", s) return forward{}, fmt.Errorf("invalid forward %q: expected local-port:remote-host:remote-port", s)
} }
return forward{listenAddr: ":" + s[:i], target: s[i+1:]}, nil return forward{listenAddr: ":" + localPort, target: target}, nil
} }
// connEntry tracks an active proxied connection pair. // connEntry tracks an active proxied connection pair.