Skip to content

Commit 6a1450c

Browse files
committed
fixing grpc url generation, changing CLI param server_ip to server
1 parent 0d974c7 commit 6a1450c

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ libc = "0.2"
5555
pelite = "0.10"
5656
regex = "1.10"
5757
structopt = "0.3.26"
58+
url-builder = "0.1.1"
5859

5960
[build-dependencies]
6061
tonic-build = "0.12.3"

src/bin/feos_cli/client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub mod feos_grpc {
1919
#[structopt(name = "feos-cli")]
2020
pub struct Opt {
2121
#[structopt(short, long, default_value = "::1")]
22-
pub server_ip: String,
22+
pub server: String,
2323
#[structopt(short, long, default_value = "1337")]
2424
pub port: u16,
2525
#[structopt(subcommand)]
@@ -78,7 +78,7 @@ fn format_address(ip: &str, port: u16) -> String {
7878
}
7979

8080
pub async fn run_client(opt: Opt) -> Result<(), Box<dyn std::error::Error>> {
81-
let address = format_address(&opt.server_ip, opt.port);
81+
let address = format_address(&opt.server, opt.port);
8282
let endpoint = Endpoint::from_shared(address)?
8383
.keep_alive_while_idle(true)
8484
.keep_alive_timeout(Duration::from_secs(20));
@@ -88,12 +88,12 @@ pub async fn run_client(opt: Opt) -> Result<(), Box<dyn std::error::Error>> {
8888

8989
match opt.cmd {
9090
Command::Container(container_cmd) => {
91-
crate::client_container::run_container_client(opt.server_ip, opt.port, container_cmd)
91+
crate::client_container::run_container_client(opt.server, opt.port, container_cmd)
9292
.await?;
9393
}
9494
Command::IsolatedContainer(container_cmd) => {
9595
crate::client_isolated_container::run_isolated_container_client(
96-
opt.server_ip,
96+
opt.server,
9797
opt.port,
9898
container_cmd,
9999
)

src/bin/feos_cli/client_container.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use tonic::Request;
66

77
use container_grpc::container_service_client::ContainerServiceClient;
88
use container_grpc::*;
9+
use url_builder::URLBuilder;
910

1011
pub mod container_grpc {
1112
tonic::include_proto!("container");
@@ -33,11 +34,16 @@ pub enum ContainerCommand {
3334
}
3435

3536
pub async fn run_container_client(
36-
server_ip: String,
37+
server: String,
3738
port: u16,
3839
cmd: ContainerCommand,
3940
) -> Result<(), Box<dyn std::error::Error>> {
40-
let address = format!("http://{}:{}", server_ip, port);
41+
let mut ub = URLBuilder::new();
42+
ub.set_protocol("http")
43+
.set_host(server.as_str())
44+
.set_port(port);
45+
let address = ub.build();
46+
4147
let channel = Endpoint::from_shared(address)?.connect().await?;
4248
let mut client = ContainerServiceClient::new(channel);
4349

src/bin/feos_cli/client_isolated_container.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use tonic::Request;
66

77
use isolated_container_grpc::isolated_container_service_client::IsolatedContainerServiceClient;
88
use isolated_container_grpc::*;
9+
use url_builder::URLBuilder;
910

1011
pub mod isolated_container_grpc {
1112
tonic::include_proto!("isolated_container");
@@ -30,11 +31,16 @@ pub enum IsolatedContainerCommand {
3031
}
3132

3233
pub async fn run_isolated_container_client(
33-
server_ip: String,
34+
server: String,
3435
port: u16,
3536
cmd: IsolatedContainerCommand,
3637
) -> Result<(), Box<dyn std::error::Error>> {
37-
let address = format!("http://{}:{}", server_ip, port);
38+
let mut ub = URLBuilder::new();
39+
ub.set_protocol("http")
40+
.set_host(server.as_str())
41+
.set_port(port);
42+
let address = ub.build();
43+
3844
let channel = Endpoint::from_shared(address)?.connect().await?;
3945
let mut client = IsolatedContainerServiceClient::new(channel);
4046

0 commit comments

Comments
 (0)