normalizeURL checks for http/https protocol, appends "http" as default protocol if not defined in url
(addr string)
| 331 | |
| 332 | // normalizeURL checks for http/https protocol, appends "http" as default protocol if not defined in url |
| 333 | func normalizeURL(addr string) (*url.URL, error) { |
| 334 | addr = strings.TrimSpace(addr) |
| 335 | |
| 336 | u, err := url.Parse(addr) |
| 337 | if err != nil { |
| 338 | return nil, err |
| 339 | } |
| 340 | |
| 341 | if u.Opaque != "" { |
| 342 | u.Host = net.JoinHostPort(u.Scheme, u.Opaque) |
| 343 | u.Opaque = "" |
| 344 | } else if u.Path != "" && !strings.Contains(u.Path, ":") { |
| 345 | u.Host = net.JoinHostPort(u.Path, "8888") |
| 346 | u.Path = "" |
| 347 | } else if u.Scheme == "" { |
| 348 | u.Host = u.Path |
| 349 | u.Path = "" |
| 350 | } |
| 351 | |
| 352 | if u.Scheme != "https" { |
| 353 | u.Scheme = "http" |
| 354 | } |
| 355 | |
| 356 | _, port, err := net.SplitHostPort(u.Host) |
| 357 | if err != nil { |
| 358 | _, port, err = net.SplitHostPort(u.Host + ":8888") |
| 359 | if err != nil { |
| 360 | return nil, err |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | if port != "" { |
| 365 | _, err = strconv.Atoi(port) |
| 366 | if err != nil { |
| 367 | return nil, err |
| 368 | } |
| 369 | } |
| 370 | return u, nil |
| 371 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…