mirror of
https://github.com/therootcompany/golib.git
synced 2026-03-02 23:57:59 +00:00
ref(cmd/tcpfwd): simplify parseForward with strings.Cut
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3f16e89f5c
commit
f9e06f131b
@ -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.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user