ParseDialTarget returns the network and address to pass to dialer.
(target string)
| 605 | |
| 606 | // ParseDialTarget returns the network and address to pass to dialer. |
| 607 | func ParseDialTarget(target string) (string, string) { |
| 608 | net := "tcp" |
| 609 | m1 := strings.Index(target, ":") |
| 610 | m2 := strings.Index(target, ":/") |
| 611 | // handle unix:addr which will fail with url.Parse |
| 612 | if m1 >= 0 && m2 < 0 { |
| 613 | if n := target[0:m1]; n == "unix" { |
| 614 | return n, target[m1+1:] |
| 615 | } |
| 616 | } |
| 617 | if m2 >= 0 { |
| 618 | t, err := url.Parse(target) |
| 619 | if err != nil { |
| 620 | return net, target |
| 621 | } |
| 622 | scheme := t.Scheme |
| 623 | addr := t.Path |
| 624 | if scheme == "unix" { |
| 625 | if addr == "" { |
| 626 | addr = t.Host |
| 627 | } |
| 628 | return scheme, addr |
| 629 | } |
| 630 | } |
| 631 | return net, target |
| 632 | } |