parseCLIURL parses a CLI URL into host and port components. Supports formats: "host:port", "http://host:port", "https://host:port", or just "port". Panics if the URL format is invalid or the port is out of range.
(url string)
| 296 | // Supports formats: "host:port", "http://host:port", "https://host:port", or just "port". |
| 297 | // Panics if the URL format is invalid or the port is out of range. |
| 298 | func parseCLIURL(url string) (string, int) { |
| 299 | // Remove protocol if present |
| 300 | cleanURL, _ := strings.CutPrefix(url, "https://") |
| 301 | cleanURL, _ = strings.CutPrefix(cleanURL, "http://") |
| 302 | |
| 303 | // Parse host:port or port format |
| 304 | var host string |
| 305 | var portStr string |
| 306 | if before, after, found := strings.Cut(cleanURL, ":"); found { |
| 307 | host = before |
| 308 | portStr = after |
| 309 | } else { |
| 310 | // Only port provided |
| 311 | portStr = before |
| 312 | } |
| 313 | |
| 314 | if host == "" { |
| 315 | host = "localhost" |
| 316 | } |
| 317 | |
| 318 | // Validate port |
| 319 | port, err := strconv.Atoi(portStr) |
| 320 | if err != nil || port <= 0 || port > 65535 { |
| 321 | panic(fmt.Sprintf("Invalid port in URIConnection: %s", url)) |
| 322 | } |
| 323 | |
| 324 | return host, port |
| 325 | } |
| 326 | |
| 327 | // Start starts the CLI server (if not using an external server) and establishes |
| 328 | // a connection. |
no outgoing calls
no test coverage detected
searching dependent graphs…