EndPoint.from constructor
EndPoint.from(
- String path
Construct an EndPoint from given path
Implementation
factory EndPoint.from(String path) {
late int port;
late String host;
final parts = path.split(':');
switch (parts.length) {
case 1:
host = parts[0];
port = Defaults.GrpcPort;
break;
case 2:
{
host = parts[0];
if (int.tryParse(parts[1]) == null) {
throw InvalidHostException(path);
}
port = int.parse(parts[1]);
break;
}
default:
throw InvalidHostException(path);
}
final address = InternetAddress.tryParse(host);
if (address != null) {
return EndPoint(
parts[0],
port,
);
}
final uri = Uri.tryParse(host);
if (uri == null) {
throw InvalidHostException(path);
}
return EndPoint(host, port);
}