ParseInstanceKey will parse an InstanceKey from a string representation such as 127.0.0.1:3306
(hostPort string)
| 35 | |
| 36 | // ParseInstanceKey will parse an InstanceKey from a string representation such as 127.0.0.1:3306 |
| 37 | func NewRawInstanceKey(hostPort string) (*InstanceKey, error) { |
| 38 | var hostname, port string |
| 39 | if submatch := ipv4HostPortRegexp.FindStringSubmatch(hostPort); len(submatch) > 0 { |
| 40 | hostname = submatch[1] |
| 41 | port = submatch[2] |
| 42 | } else if submatch := ipv4HostRegexp.FindStringSubmatch(hostPort); len(submatch) > 0 { |
| 43 | hostname = submatch[1] |
| 44 | } else if submatch := ipv6HostPortRegexp.FindStringSubmatch(hostPort); len(submatch) > 0 { |
| 45 | hostname = submatch[1] |
| 46 | port = submatch[2] |
| 47 | } else if submatch := ipv6HostRegexp.FindStringSubmatch(hostPort); len(submatch) > 0 { |
| 48 | hostname = submatch[1] |
| 49 | } else { |
| 50 | return nil, fmt.Errorf("cannot parse address: %s", hostPort) |
| 51 | } |
| 52 | instanceKey := &InstanceKey{Hostname: hostname, Port: DefaultInstancePort} |
| 53 | if port != "" { |
| 54 | var err error |
| 55 | if instanceKey.Port, err = strconv.Atoi(port); err != nil { |
| 56 | return instanceKey, fmt.Errorf("invalid port: %s", port) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return instanceKey, nil |
| 61 | } |
| 62 | |
| 63 | // ParseInstanceKey will parse an InstanceKey from a string representation such as 127.0.0.1:3306. |
| 64 | // The port part is optional; there will be no name resolve |
no test coverage detected
searching dependent graphs…