ParseIPPort return ip port
(s string)
| 168 | |
| 169 | //ParseIPPort return ip port |
| 170 | func ParseIPPort(s string) (string, error) { |
| 171 | i := strings.Index(s, ":") |
| 172 | if i < 0 { |
| 173 | return "", errors.New("[p2p]split ip port error") |
| 174 | } |
| 175 | port, err := strconv.Atoi(s[i+1:]) |
| 176 | if err != nil { |
| 177 | return "", errors.New("[p2p]parse port error") |
| 178 | } |
| 179 | if port <= 0 || port >= 65535 { |
| 180 | return "", errors.New("[p2p]port out of bound") |
| 181 | } |
| 182 | return s[i:], nil |
| 183 | } |