ParseGatewayServerAddress parses gateway server address s into hostname and port, port is equal to the port contained in s or DefaultGatewayServerUDPPort otherwise.
(s string)
| 383 | // ParseGatewayServerAddress parses gateway server address s into hostname and port, |
| 384 | // port is equal to the port contained in s or DefaultGatewayServerUDPPort otherwise. |
| 385 | func ParseGatewayServerAddress(s string) (string, uint16, error) { |
| 386 | host, portStr, err := net.SplitHostPort(s) |
| 387 | if err != nil { |
| 388 | if host, _, err := net.SplitHostPort(fmt.Sprintf("%s:1700", s)); err == nil && host != "" { |
| 389 | return host, 1700, nil |
| 390 | } |
| 391 | return "", 0, errInvalidGatewayServerAddress.WithCause(err) |
| 392 | } |
| 393 | if host == "" { |
| 394 | return "", 0, errInvalidGatewayServerAddress.WithCause(errEmptyGatewayServerAddress) |
| 395 | } |
| 396 | port, err := strconv.ParseUint(portStr, 10, 16) |
| 397 | if err != nil { |
| 398 | return "", 0, errInvalidGatewayServerAddress.WithCause(err) |
| 399 | } |
| 400 | return host, uint16(port), nil |
| 401 | } |