Skip to content

Commit

Permalink
Rust SDK: Add parametric host address (#3111)
Browse files Browse the repository at this point in the history
Add `new_with_host` to allow specifying the host address.
  • Loading branch information
MiniaczQ authored May 18, 2023
1 parent 0137747 commit 4408cfc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
13 changes: 3 additions & 10 deletions sdks/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

[package]
name = "agones"
version = "0.2.0"
version = "0.2.1"
edition = "2018"
license = "Apache-2.0"
repository = "https://github.com/googleforgames/agones"
Expand All @@ -35,16 +35,9 @@ features = ["sync", "time"]
[dependencies.tonic]
version = "0.5"
default-features = false
features = [
"codegen",
"transport",
"prost",
]
features = ["codegen", "transport", "prost"]

[build-dependencies.tonic-build]
version = "0.5"
default-features = false
features = [
"prost",
"transport",
]
features = ["prost", "transport"]
29 changes: 29 additions & 0 deletions sdks/rust/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,35 @@ impl Sdk {
)
.parse()?;

Self::new_internal(addr, keep_alive).await
}

pub async fn new_with_host(
host: Option<String>,
port: Option<u16>,
keep_alive: Option<Duration>,
) -> Result<Self> {
let addr: http::Uri = format!(
"{}:{}",
host.unwrap_or_else(|| {
env::var("AGONES_SDK_GRPC_HOST")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or("http://localhost".to_owned())
}),
port.unwrap_or_else(|| {
env::var("AGONES_SDK_GRPC_PORT")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(9357)
})
)
.parse()?;

Self::new_internal(addr, keep_alive).await
}

async fn new_internal(addr: http::Uri, keep_alive: Option<Duration>) -> Result<Self> {
let builder = tonic::transport::channel::Channel::builder(addr)
.connect_timeout(Duration::from_secs(30))
.keep_alive_timeout(keep_alive.unwrap_or_else(|| Duration::from_secs(30)));
Expand Down

0 comments on commit 4408cfc

Please sign in to comment.