parseRemotePath parses a remote path string (host:path or [host]:path) and returns the host/alias part and the path part.
(s string)
| 25 | // parseRemotePath parses a remote path string (host:path or [host]:path) and returns |
| 26 | // the host/alias part and the path part. |
| 27 | func parseRemotePath(s string) (host, path string, ok bool) { |
| 28 | if strings.HasPrefix(s, "[") { |
| 29 | closeBracket := strings.Index(s, "]") |
| 30 | if closeBracket < 0 { |
| 31 | return "", "", false |
| 32 | } |
| 33 | host = s[1:closeBracket] |
| 34 | rest := s[closeBracket+1:] |
| 35 | if rest == "" { |
| 36 | return host, "", false |
| 37 | } |
| 38 | if rest[0] == ':' { |
| 39 | if len(rest) == 1 { |
| 40 | return host, "", false |
| 41 | } |
| 42 | return host, rest[1:], true |
| 43 | } |
| 44 | return host, rest, true |
| 45 | } |
| 46 | parts := strings.SplitN(s, ":", 2) |
| 47 | if len(parts) == 2 && parts[1] != "" { |
| 48 | return parts[0], parts[1], true |
| 49 | } |
| 50 | return "", "", false |
| 51 | } |
| 52 | |
| 53 | // formatRemotePath builds a "host:path" string, wrapping IPv6 addresses in brackets. |
| 54 | func formatRemotePath(host, path string) string { |
no outgoing calls