MCPcopy Index your code
hub / github.com/github/gh-ost / NewRawInstanceKey

Function NewRawInstanceKey

go/mysql/instance_key.go:37–61  ·  view source on GitHub ↗

ParseInstanceKey will parse an InstanceKey from a string representation such as 127.0.0.1:3306

(hostPort string)

Source from the content-addressed store, hash-verified

35
36// ParseInstanceKey will parse an InstanceKey from a string representation such as 127.0.0.1:3306
37func 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

Callers 1

ParseInstanceKeyFunction · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…